我必须选择具有数据库权限的所有用户(例如数据库'mysql')。有什么建议?感谢。
答案 0 :(得分:25)
所有用户及其近似特权的良好视图。如果有密码,它将通过加密字符串;如果没有,此字段为空白。选择是一种非常普遍的特权; insert允许在数据库中进行表操作; shutdown允许主要系统更改,并且只能由root用户使用;授予权限的能力与其他权限是分开的。
SELECT user, host, password, select_priv, insert_priv, shutdown_priv, grant_priv
FROM mysql.user
查看各个数据库的权限。
SELECT user, host, db, select_priv, insert_priv, grant_priv FROM mysql.db
答案 1 :(得分:13)
database privileges存储在mysql.db
table privileges存储在mysql.tables_priv
column privileges存储在mysql.columns_priv
routine privileges存储在mysql.proc_privs
您可以定义商店过程以列出权限:
delimiter //
CREATE PROCEDURE list_privileges (IN db_name CHAR(50))
BEGIN
SELECT concat(Db,'.', '*') as 'what', User, Host, '...' as 'perms'
FROM mysql.db
WHERE Db=db_name
UNION
SELECT concat(Db,'.', Table_name), User, Host, table_priv
FROM mysql.tables_priv
WHERE Db=db_name and table_priv != ''
UNION
SELECT concat(Db,'.', Table_name, '(', Column_name,')'), User, Host, Column_priv
FROM mysql.columns_priv
WHERE Db=db_name
UNION
SELECT concat(Db,'.', Routine_name, '()'), User, Host, Proc_priv
FROM mysql.procs_priv
WHERE Db=db_name;
END//
delimiter ;
示例:
mysql> call list_privileges("testlink2");
+-----------------------------+-----------+-----------+---------+
| what | User | Host | perms |
+-----------------------------+-----------+-----------+---------+
| testlink2.* | testlink2 | % | ... |
| testlink2.* | testlink2 | localhost | ... |
| testlink2.executions | testlink2 | % | Select |
| testlink2.users(id) | testlink2 | % | Select |
| testlink2.list_privileges() | testlink2 | % | Execute |
+-----------------------------+-----------+-----------+---------+
5 rows in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
答案 2 :(得分:8)
查看mysql
数据库(mysql服务器中名为mysql
的实际数据库,只是为了清楚)。有三个表(db
,tables_priv
和columns_priv
),其中存储了db / table / column privs:
SELECT 'db', User, Host
FROM db
WHERE Db='mydatabase'
UNION
SELECT 'table', User, Host
FROM tables_priv
WHERE Db='mydatabase'
UNION
SELECT 'col', User, Host
FROM columns_priv
WHERE Db='mydatabase'
应该告诉你你需要什么。