MySQL支持的權限以下:
ALL或ALL PRIVILEGES 表明指定權限等級的全部權限。
ALTER 容許使用ALTER TABLE來改變表的結構,ALTER TABLE同時也須要CREATE和INSERT權限。重命名一個表須要對舊錶具備ALTER和DROP權限,對新版具備CREATE和INSERT權限。
ALTER ROUTINE 容許改變和刪除存儲過程和函數
CREATE 容許建立新的數據庫和表
CREATE ROUTINE 容許建立建立存儲過程和包
CREATE TABLESPACE 容許建立、更改和刪除表空間和日誌文件組
CREATE TEMPORARY TABLES 容許建立臨時表
CREATE USER 容許更改、建立、刪除、重命名用戶和收回全部權限
CREATE VIEW 容許建立視圖
DELETE 容許從數據庫的表中刪除行
DROP 容許刪除數據庫、表和視圖
EVENT 容許在事件調度裏面建立、更改、刪除和查看事件
EXECUETE 容許執行存儲過程和包
FILE 容許在服務器的主機上經過LOAD DATA INFILE、SELECT ... INTO OUTFILE和LOAD_FILE()函數讀寫文件
GRANT OPTION 容許向其餘用戶授予或移除權限
INDEX 容許建立和刪除索引
INSERT 容許向數據庫的表中插入行
LOCK TABLE 容許執行LOCK TABLES語句來鎖定表
PROCESS 容許顯示在服務器上執行的線程信息,即被會話所執行的語句信息。這個權限容許你執行SHOW PROCESSLIST和mysqladmin processlist命令來查看線程,同時這個權限也容許你執行SHOW ENGINE命令
PROXY 容許用戶冒充成爲另一個用戶
REFERENCES 容許建立外鍵
RELOAD 容許使用FLUSH語句
REPLICATION CLIENT 容許執行SHOW MASTER STATUS,SHOW SLAVE STATUS和SHOW BINARY LOGS命令
REPLICATION SLAVE 容許SLAVE服務器鏈接到當前服務器來做爲他們的主服務器
SELECT 容許從數據庫中查詢表
SHOW DATABASES 容許帳戶執行SHOW DATABASE語句來查看數據庫。沒有這個權限的帳戶只能看到他們具備權限的數據庫。
SHOW VIEW 容許執行SHOW CREATE VIEW語句
SHUTDOWN 容許執行SHUTDOWN語句和mysqladmin shutdown已經mysql_shutdown() C API函數
SUPER 容許用戶執行CHANGE MASTER TO,KILL或mysqladmin kill命令來殺掉其餘用戶的線程,容許執行PURGE BINARY LOGS命令,經過SET GLOBAL來設置系統參數,執行mysqladmin debug命令,開啓和關閉日誌,即便read_only參數開啓也能夠執行update語句,打開和關閉從服務器上面的複製,容許在鏈接數達到max_connections的狀況下鏈接到服務器。
TRIGGER 容許操做觸發器
UPDATE 容許更新數據庫中的表
USAGE 表明沒有任何權限
授予全局權限:
*.*表明全部數據庫的權限
mysql> grant all on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select, insert on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
授予指定數據庫的權限:
mysql> grant all on test.* to 'test'@'localhost';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> grant select, insert on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select, insert on test.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)
授予指定表的權限:
mysql> grant all on test.orders to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.13 sec)
mysql> grant select, insert on test.orders to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.07 sec)
授予指定字段的權限:
mysql> desc test.orders_1;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| order_date | date | YES | | NULL | |
| order_id | int(11) | YES | | NULL | |
| customer_name | varchar(15) | YES | | NULL | |
| product_id | int(11) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> grant select(order_date), insert(order_id,customer_name) on test.orders_1 to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.01 sec)
[root@T400-kelong ~]# mysql -ujeffrey -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.10-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from orders_1;
ERROR 1142 (42000): SELECT command denied to user 'jeffrey'@'localhost' for table 'orders_1'
mysql> select order_date from orders_1;
+------------+
| order_date |
+------------+
| 2016-03-26 |
+------------+
1 row in set (0.00 sec)
授予存儲過程的權限:
mysql> grant create routine on test.* to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.08 sec)
mysql> grant execute on procedure test.myproc to 'jeffrey'@'localhost';
Query OK, 0 rows affected (0.04 sec)
授予代理用戶權限:
PROX權限能夠使一個用戶成爲另一個用戶的代理
mysql> grant proxy on 'jeffrey'@'localhost' to 'test'@'%';
Query OK, 0 rows affected (0.09 sec)mysql