Answers:
以管理员用户(通常以root用户身份)连接到mysql实例,并给出以下命令...
select user from mysql.db where db='DB_NAME';
select user from mysql.db
无条件运行也会返回2个空白行。
user79644的答案使用户具有数据库级特权,但是会错过仅具有表级,列级或过程级特权的用户。若要查找所有这些,请使用以下语句:
SELECT user,host FROM db WHERE db='name';
SELECT user,host FROM tables_priv WHERE db='name';
SELECT user,host FROM columns_priv WHERE db='name';
SELECT user,host FROM procs_priv WHERE db='name';
至少在MySQL 5.5中,似乎具有列级特权意味着您具有表级特权。拥有表级特权并不意味着您具有数据库级特权。不确定过程级特权。
ERROR 1046 (3D000): No database selected
mysql
数据库。那是MySQL使用的所有数据存储的地方。给出USE mysql;
将数据库名称添加到表名称的命令,例如FROM mysql.db
或FROM mysql.tables_priv
# current users that access the db
mysql> show processlist;
+-----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+------+---------+------+-------+------------------+
| 214 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+-----+------+-----------+------+---------+------+-------+------------------+
# who can access what at anytime and his privilege level
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
# what privileges are available
mysql> show privileges;
您必须记住,用于数据库的MySQLGRANT
可以包含通配符。这必须通过LIKE
在查询中使用来解决:
SELECT user,host FROM db WHERE 'name' LIKE db;
SELECT user,host FROM tables_priv WHERE db='name';
SELECT user,host FROM columns_priv WHERE db='name';
SELECT user,host FROM procs_priv WHERE db='name';