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
  • 相关阅读:
    面试题目以及注意事项
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    前端知识大全
    jquery实现2级联动
    [转]那些年我们一起清除过的浮动
    使用kubeadm在CentOS上搭建Kubernetes1.14.3集群
    企业优秀运维人员20道必会iptables面试题
    通过nginx日志利用shell统计日pv和uv
    php访问mysql接口pdo-mysql安装
    何查看已经安装的nginx、apache、mysql和php的编译参数
  • 原文地址:https://www.cnblogs.com/jec1999/p/11678572.html
Copyright © 2011-2022 走看看