GRANT語句能夠用於進行受權和設置角色,須要有 GRANT OPTION 權限或 mysql 系統表的 UPDATE 權限。mysql
不能在一個GRANT語句中同時進行受權和設置角色。GRANT語句使用ON
子句區分是進行受權仍是設置角色。sql
ON
子句則爲受權。ON
子句則爲設置角色。GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; GRANT 'role1', 'role2' TO 'user1'@'localhost', 'user2'@'localhost'; GRANT SELECT ON world.* TO 'role3';
適用於全部數據庫,全局權限存儲在 mysql.user
系統表中。數據庫
GRANT ALL ON *.* TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';
適用於給定數據庫中的全部對象,數據庫權限存儲在 mysql.db
系統表中。ide
GRANT ALL ON mydb.* TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON mydb.* TO 'someuser'@'somehost';
適用於給定表中的全部列,表權限存儲在 mysql.tables_priv
系統表中。代理
GRANT ALL ON mydb.mytbl TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON mydb.mytbl TO 'someuser'@'somehost';
適用於給定表中的單個列,列權限存儲在 mysql.columns_priv
系統表中。code
GRANT SELECT (col1), INSERT (col1, col2) ON mydb.mytbl TO 'someuser'@'somehost';
略對象
略it
GRANT 'role1', 'role2' TO 'user1'@'localhost', 'user2'@'localhost';
mysql> SHOW GRANTS FOR 'someuser'@'somehost'; +-------------------------------------------------------+ | Grants for admin@localhost | +-------------------------------------------------------+ | GRANT RELOAD, PROCESS ON *.* TO 'someuser'@'somehost' | +-------------------------------------------------------+
mysql> SET print_identified_with_as_hex = ON; mysql> SHOW CREATE USER 'admin'@'localhost'\G *************************** 1. row *************************** CREATE USER for admin@localhost: CREATE USER 'admin'@'localhost' IDENTIFIED WITH 'caching_sha2_password' AS 0x24412430303524301D0E17054E2241362B1419313C3E44326F294133734B30792F436E77764270373039612E32445250786D43594F45354532324B6169794F47457852796E32 REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT