zoukankan      html  css  js  c++  java
  • MySQL:用户,权限,配置文件,忘记root密码

    mysql中的用户是使用 用户名@ip 来标识的

    增删改查:

    mysql> create user yang@'10.0.0.1' identified by '123';
    mysql> create user yang@"%" identified by '123';
    mysql> drop user yang@'10.0.0.1';
    mysql> alter user root@'%' identified by '123456';
    mysql> select User,Host,authentication_string from mysql.user;

    权限管理 

    grant 权限  on 范围  to  用户  identified by 密码;
    
    权限:
        ALL : SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, 
        REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES,
        EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, 
        SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE
        with grant option
    范围:
    *.*       chmod xxx -R /
    库.*      chmod xxx -R /oldguo
    库.表     chmod xxx -R /oldguo/a.txt 
    
    mysql> grant all on *.* to oldguo@'10.0.0.%' identified by '123';
    mysql> grant SELECT,INSERT, UPDATE, DELETE on *.* to oldboy@'10.0.0.%' identified by '123';
    
    revoke
    mysql> show grants for oldboy@'10.0.0.%';
    mysql> revoke delete on *.* from oldboy@'10.0.0.%';
    mysql> show grants for oldboy@'10.0.0.%';

    配置文件

    (1) 默认读取顺序
    [root@db01 ~]# mysqld --help --verbose |grep my.cnf
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

    忘记root密码

    (1) 关闭数据库,并启动到安全模式
    [root@db01 ~]# systemctl stop mysqld
    [root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &
    (2) 登录数据库修改密码
    mysql> flush privileges;
    mysql> alter user root@'localhost' identified by '1';
    
    (3) kill掉mysqld_safe进程
    [root@db01 ~]# ps aux | grep mysql
    [root@db01 ~]# kill -9 xxx
    
    (3) 正常重启数据库
    [root@db01 ~]# systemctl start mysqld
  • 相关阅读:
    python高级 之(三) --- 高阶函数
    python高级 之(二) --- 类装饰器
    python高级 之(一) --- 函数类型
    jQuery
    css
    html
    px2rem
    keep-alive标签
    rem适配方案2(flexible.js)
    媒体查询
  • 原文地址:https://www.cnblogs.com/jec1999/p/11678572.html
Copyright © 2011-2022 走看看