首页 > 数据库 > MySQL > 正文

MySQL查询用户权限的方法总结

2024-07-24 12:54:35
字体:
来源:转载
供稿:网友

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

1、 使用MySQL grants命令

mysql> show grants for username@localhost;+---------------------------------------------------------------------+| Grants for root@localhost |+---------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |+---------------------------------------------------------------------+

需要注意的是:

● username和ip的组合需要是在mysql.user表中存在的,具体可以通过 select * from mysql.user 命令查看

● ip地址如果是通配符格式需要加引号,例如:show grants for root@'172.%';

2、 使用MySQL select命令

mysql> select * from mysql.user where user='root' and host='localhost' /G;*************************** 1. row ***************************Host: localhostUser: rootPassword: **********************Select_priv: YInsert_priv: YUpdate_priv: YDelete_priv: YCreate_priv: YDrop_priv: YReload_priv: YShutdown_priv: YProcess_priv: YFile_priv: YGrant_priv: YReferences_priv: YIndex_priv: YAlter_priv: YShow_db_priv: YSuper_priv: YCreate_tmp_table_priv: YLock_tables_priv: YExecute_priv: YRepl_slave_priv: YRepl_client_priv: YCreate_view_priv: YShow_view_priv: YCreate_routine_priv: YAlter_routine_priv: YCreate_user_priv: YEvent_priv: YTrigger_priv: YCreate_tablespace_priv: Yssl_type:ssl_cipher:x509_issuer:x509_subject:max_questions: 0max_updates: 0max_connections: 0max_user_connections: 0plugin: mysql_native_passwordauthentication_string:password_expired: N1 row in set (0.01 sec)

 

知识点扩展:

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

mysql> drop user test;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> grant all on MyDB.kkk to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> mysql> show grants for test;+-----------------------------------------------------------------------------------------------------+| Grants for test@% |+-----------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' || GRANT ALL PRIVILEGES ON `MyDB`.`kkk` TO 'test'@'%' |+-----------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)mysql> select * from mysql.tables_priv/G;*************************** 1. row ***************************Host: %Db: MyDBUser: testTable_name: kkkGrantor: root@localhostTimestamp: 0000-00-00 00:00:00Table_priv: Select,Insert,Update,Delete,Create,Drop,References,Index,Alter,Create View,Show view,TriggerColumn_priv: 1 row in set (0.01 sec)ERROR: No query specifiedmysql> <br>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表