lijfustc

导航

 

1、配置文件

  • mysql --help --verbose | grep my.cnf

  

 

2、系统变量

  • show variables like 'long%query%';

  

 

  • show global variables like 'long%query%';

  

 

  • show variables like 'log_error';

  

 

  • show variables like 'datadir';  

  

 

  • show tables like '%variables%';

  

 

  • select * from variables_by_thread where variable_name = 'long_query_time';

  

 

  • show processlist;    --显示的是:connection_id

  

 

  • select connection_id();

  

 

  • select * from threads where thread_id=46 \G

  

 

3、用户权限管理(Mysql5.7)

  • 注:Mysql8.0开始,可以用role来管理。  
  • create user 'david'@'192.168.%' identified by '123'; --创建用户

  

 

  • select host,user from user;  --查看用户

  

 

  • show grants for 'david'@'192.168.%';  --查看权限

  

 

  • grant select,update,insert,delete on test.* to 'david'@'192.168.%';   --授予权限
    • 注意:如果想让david可以将select,update,insert,delete权限授予别的用户,那么可以在后面加上: with grant option
      • 命令:grang select,update,insert,delete on test.* to 'david'@'192.168.%' with grant option;
  • alter user 'david'@'192.168.%' identified by '456';   --改密码

  

 

  • show grants for 'david'@'192.168.%'; --查看权限

  

 

  • revoke delete on test.* from 'david'@'192.168.%';  --删除权限(delete权限)
    • 注意:revoke仅删除权限,不删除用户。
    • 比如:revoke all on test.* from 'david'@'192.168.%',删除用户的所有权限,但不删除用户。
      • 注意点:这个命令(revoke all on test.* from ...) 不会删除 USAGE权限。

  

 

  • show grants for 'david'@'192.168.%';  --再次查看权限,delete权限没有了。

  

 

 

  • drop user 'david'@'192.168.%' ; --删除用户

  

 

  • select host,user from user;  --查看用户

  

 

  • select host,user,authentication_string from user;  --查看用户

  

  

  • select * from user where user='david' \G   -- 查看的是user表
    • 注意:这里 select_priv, insert_priv, update_priv  都是N, 表示 没有全局的select,insert,update权限,只有表级(test.*)的权限

  

 

  • select * from db where user='david' \G。--查看的是 db表
    • 对于test这个表,有 select,insert,update 权限。
    • 注意:因为没有with grant option,所以 grant_priv 是 N,不是Y

  

 

posted on 2022-05-17 22:20  lijfustc  阅读(76)  评论(0)    收藏  举报