怎么在MySQL中查询用户权限

  介绍

怎么在MySQL中查询用户权限?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

<强>介绍两种查看MySQL用户权限的两种方法

1,使用MySQL赠款命令

mysql>, show  grants  for  username@localhost;      + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +      |,Grants  for  root@localhost  |      + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +      |,GRANT  ALL  PRIVILEGES 提醒*。*,用& # 39;根# 39;@ # 39;localhost # 39; WITH  GRANT  OPTION  |      + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +

需要注意的是:

●用户名和ip的组合需要是在mysql。用户表中存在的,具体可以通过select *从mysql。用户命令查看

●ip地址如果是通配符格式需要加引号,例如:显示赠款root@& # 39; & # 39; 172.%;

2,使用MySQL选择命令

mysql>, select  *,得到mysql.user  where 用户=& # 39;根# 39;,以及主机=& # 39;localhost # 39;, \ G;   * * * * * * * * * * * * * * * * * * * * * * * * * * *,1只row  * * * * * * * * * * * * * * * * * * * * * * * * * * *   主持人:localhost   用户:根   密码:* * * * * * * * * * * * * * * * * * * * * *   Select_priv: Y   Insert_priv: Y   Update_priv: Y   Delete_priv: Y   Create_priv: Y   Drop_priv: Y   Reload_priv: Y   Shutdown_priv: Y   Process_priv: Y   File_priv: Y   Grant_priv: Y   References_priv: Y   Index_priv: Y   Alter_priv: Y   Show_db_priv: Y   Super_priv: Y   Create_tmp_table_priv: Y   Lock_tables_priv: Y   Execute_priv: Y   Repl_slave_priv: Y   Repl_client_priv: Y   Create_view_priv: Y   Show_view_priv: Y   Create_routine_priv: Y   Alter_routine_priv: Y   Create_user_priv: Y   Event_priv: Y   Trigger_priv: Y   Create_tablespace_priv: Y   ssl_type:   ssl_cipher:   x509_issuer:   x509_subject:   max_questions: 0   max_updates: 0   max_connections: 0   max_user_connections: 0   插件:mysql_native_password   authentication_string:   password_expired: N   1,row  set 拷贝;(0.01,sec)

知识点扩展:

我们来创建一个测试账号测试,授予表层级的权限

mysql>, drop  user 测试;   Query 好吧,,0,rows  affected (0.00,秒)   mysql>, flush 特权;   Query 好吧,,0,rows  affected (0.00,秒)   mysql>, grant  all 提醒MyDB.kkk 用test@& # 39; % & # 39;, identified  by  & # 39;测试# 39;;   Query 好吧,,0,rows  affected (0.01,秒)   mysql>,   mysql>, show  grants  for 测试;   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   |,Grants  for  test@ % |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   |,GRANT  USAGE 提醒*。*,用& # 39;测试# 39;@ # 39;% & # 39;,IDENTIFIED  BY  PASSWORD  & # 39; * 94 bdcebe19083ce2a1f959fd02f964c7af4cfc29& # 39; |   |,GRANT  ALL  PRIVILEGES 提醒“MyDB”。“三k党”,用& # 39;测试# 39;@ # 39;% & # 39;|   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   2,rows  set 拷贝;(0.00,sec)   mysql>, select  *,得到mysql.tables_priv \ G;   * * * * * * * * * * * * * * * * * * * * * * * * * * *,1只row  * * * * * * * * * * * * * * * * * * * * * * * * * * *   主持人:%   Db: MyDB   用户:测试   Table_name:三k党   委托人:root@localhost   时间戳:0000 - 00 - 00 -就是   Table_priv:选择、插入、更新、删除、创建、删除、引用、指数、涂改、Create 看来,Show 视图,触发器   Column_priv:,   1,row  set 拷贝;(0.01,sec)   错误:,   No  query 指定   mysql>, & lt; br>

怎么在MySQL中查询用户权限