本篇內容介紹了“5.7的權限介紹”的有關(guān)知識,在實(shí)際案例的操作過(guò)程中,不少人都會(huì )遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學(xué)有所成!
MySQL支持的權限如下:
ALL或ALL PRIVILEGES 代表指定權限等級的所有權限。
ALTER 允許使用ALTER TABLE來(lái)改變表的結構,ALTER TABLE同時(shí)也需要CREATE和INSERT權限。重命名一個(gè)表需要對舊表具有ALTER和DROP權限,對新版具有CREATE和INSERT權限。
ALTER ROUTINE 允許改變和刪除存儲過(guò)程和函數
CREATE 允許創(chuàng )建新的數據庫和表
CREATE ROUTINE 允許創(chuàng )建創(chuàng )建存儲過(guò)程和包
CREATE TABLESPACE 允許創(chuàng )建、更改和刪除表空間和日志文件組
CREATE TEMPORARY TABLES 允許創(chuàng )建臨時(shí)表
CREATE USER 允許更改、創(chuàng )建、刪除、重命名用戶(hù)和收回所有權限
CREATE VIEW 允許創(chuàng )建視圖
DELETE 允許從數據庫的表中刪除行
DROP 允許刪除數據庫、表和視圖
EVENT 允許在事件調度里面創(chuàng )建、更改、刪除和查看事件
EXECUETE 允許執行存儲過(guò)程和包
FILE 允許在的主機上通過(guò)LOAD DATA INFILE、SELECT ... INTO OUTFILE和LOAD_FILE()函數讀寫(xiě)文件
GRANT OPTION 允許向其他用戶(hù)授予或移除權限
INDEX 允許創(chuàng )建和刪除索引
INSERT 允許向數據庫的表中插入行
LOCK TABLE 允許執行LOCK TABLES語(yǔ)句來(lái)鎖定表
PROCESS 允許顯示在服務(wù)器上執行的線(xiàn)程信息,即被會(huì )話(huà)所執行的語(yǔ)句信息。這個(gè)權限允許你執行SHOW PROCESSLIST和mysqladmin processlist命令來(lái)查看線(xiàn)程,同時(shí)這個(gè)權限也允許你執行SHOW ENGINE命令
PROXY 允許用戶(hù)冒充成為另外一個(gè)用戶(hù)
REFERENCES 允許創(chuàng )建外鍵
RELOAD 允許使用FLUSH語(yǔ)句
REPLICATION CLIENT 允許執行SHOW MASTER STATUS,SHOW SLAVE STATUS和SHOW BINARY LOGS命令
REPLICATION SLAVE 允許SLAVE服務(wù)器連接到當前服務(wù)器來(lái)作為他們的主服務(wù)器
SELECT 允許從數據庫中查詢(xún)表
SHOW DATABASES 允許賬戶(hù)執行SHOW DATABASE語(yǔ)句來(lái)查看數據庫。沒(méi)有這個(gè)權限的賬戶(hù)只能看到他們具有權限的數據庫。
SHOW VIEW 允許執行SHOW CREATE VIEW語(yǔ)句
SHUTDOWN 允許執行SHUTDOWN語(yǔ)句和mysqladmin shutdown已經(jīng)mysql_shutdown() C API函數
SUPER 允許用戶(hù)執行CHANGE MASTER TO,KILL或mysqladmin kill命令來(lái)殺掉其他用戶(hù)的線(xiàn)程,允許執行PURGE BINARY LOGS命令,通過(guò)SET GLOBAL來(lái)設置系統參數,執行mysqladmin debug命令,開(kāi)啟和關(guān)閉日志,即使read_only參數開(kāi)啟也可以執行update語(yǔ)句,打開(kāi)和關(guān)閉從服務(wù)器上面的復制,允許在連接數達到max_connections的情況下連接到服務(wù)器。
TRIGGER 允許操作觸發(fā)器
UPDATE 允許更新數據庫中的表
USAGE 代表沒(méi)有任何權限
授予全局權限:
*.*代表所有數據庫的權限
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)
授予存儲過(guò)程的權限:
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)
授予代理用戶(hù)權限:
PROX權限可以使一個(gè)用戶(hù)成為另外一個(gè)用戶(hù)的代理
mysql> grant proxy on 'jeffrey'@'localhost' to 'test'@'%';
Query OK, 0 rows affected (0.09 sec)
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站