溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MySQL5.7的權(quán)限介紹

發(fā)布時(shí)間:2021-09-16 16:36:53 來(lái)源:億速云 閱讀:209 作者:chen 欄目:MySQL數(shù)據(jù)庫(kù)

本篇內(nèi)容介紹了“MySQL5.7的權(quán)限介紹”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

MySQL支持的權(quán)限如下:
ALL或ALL PRIVILEGES 代表指定權(quán)限等級(jí)的所有權(quán)限。
ALTER 允許使用ALTER TABLE來(lái)改變表的結(jié)構(gòu),ALTER TABLE同時(shí)也需要CREATE和INSERT權(quán)限。重命名一個(gè)表需要對(duì)舊表具有ALTER和DROP權(quán)限,對(duì)新版具有CREATE和INSERT權(quán)限。
ALTER ROUTINE 允許改變和刪除存儲(chǔ)過(guò)程和函數(shù)
CREATE 允許創(chuàng)建新的數(shù)據(jù)庫(kù)和表
CREATE ROUTINE 允許創(chuàng)建創(chuàng)建存儲(chǔ)過(guò)程和包
CREATE TABLESPACE 允許創(chuàng)建、更改和刪除表空間和日志文件組
CREATE TEMPORARY TABLES 允許創(chuàng)建臨時(shí)表
CREATE USER 允許更改、創(chuàng)建、刪除、重命名用戶和收回所有權(quán)限
CREATE VIEW 允許創(chuàng)建視圖
DELETE 允許從數(shù)據(jù)庫(kù)的表中刪除行
DROP 允許刪除數(shù)據(jù)庫(kù)、表和視圖
EVENT 允許在事件調(diào)度里面創(chuàng)建、更改、刪除和查看事件
EXECUETE 允許執(zhí)行存儲(chǔ)過(guò)程和包
FILE 允許在服務(wù)器的主機(jī)上通過(guò)LOAD DATA INFILE、SELECT ... INTO OUTFILE和LOAD_FILE()函數(shù)讀寫(xiě)文件
GRANT OPTION 允許向其他用戶授予或移除權(quán)限
INDEX 允許創(chuàng)建和刪除索引
INSERT 允許向數(shù)據(jù)庫(kù)的表中插入行
LOCK TABLE 允許執(zhí)行LOCK TABLES語(yǔ)句來(lái)鎖定表
PROCESS 允許顯示在服務(wù)器上執(zhí)行的線程信息,即被會(huì)話所執(zhí)行的語(yǔ)句信息。這個(gè)權(quán)限允許你執(zhí)行SHOW PROCESSLIST和mysqladmin processlist命令來(lái)查看線程,同時(shí)這個(gè)權(quán)限也允許你執(zhí)行SHOW ENGINE命令
PROXY 允許用戶冒充成為另外一個(gè)用戶
REFERENCES 允許創(chuàng)建外鍵
RELOAD 允許使用FLUSH語(yǔ)句
REPLICATION CLIENT 允許執(zhí)行SHOW MASTER STATUS,SHOW SLAVE STATUS和SHOW BINARY LOGS命令
REPLICATION SLAVE 允許SLAVE服務(wù)器連接到當(dāng)前服務(wù)器來(lái)作為他們的主服務(wù)器
SELECT 允許從數(shù)據(jù)庫(kù)中查詢表
SHOW DATABASES 允許賬戶執(zhí)行SHOW DATABASE語(yǔ)句來(lái)查看數(shù)據(jù)庫(kù)。沒(méi)有這個(gè)權(quán)限的賬戶只能看到他們具有權(quán)限的數(shù)據(jù)庫(kù)。
SHOW VIEW 允許執(zhí)行SHOW CREATE VIEW語(yǔ)句
SHUTDOWN 允許執(zhí)行SHUTDOWN語(yǔ)句和mysqladmin shutdown已經(jīng)mysql_shutdown() C API函數(shù)
SUPER 允許用戶執(zhí)行CHANGE MASTER TO,KILL或mysqladmin kill命令來(lái)殺掉其他用戶的線程,允許執(zhí)行PURGE BINARY LOGS命令,通過(guò)SET GLOBAL來(lái)設(shè)置系統(tǒng)參數(shù),執(zhí)行mysqladmin debug命令,開(kāi)啟和關(guān)閉日志,即使read_only參數(shù)開(kāi)啟也可以執(zhí)行update語(yǔ)句,打開(kāi)和關(guān)閉從服務(wù)器上面的復(fù)制,允許在連接數(shù)達(dá)到max_connections的情況下連接到服務(wù)器。
TRIGGER 允許操作觸發(fā)器
UPDATE 允許更新數(shù)據(jù)庫(kù)中的表
USAGE 代表沒(méi)有任何權(quán)限

授予全局權(quán)限:

*.*代表所有數(shù)據(jù)庫(kù)的權(quán)限

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)

授予指定數(shù)據(jù)庫(kù)的權(quán)限:

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)

授予指定表的權(quán)限:

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)

授予指定字段的權(quán)限:

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)

授予存儲(chǔ)過(guò)程的權(quán)限:

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)

授予代理用戶權(quán)限:

PROX權(quán)限可以使一個(gè)用戶成為另外一個(gè)用戶的代理

mysql> grant proxy on 'jeffrey'@'localhost' to 'test'@'%';
Query OK, 0 rows affected (0.09 sec)

“MySQL5.7的權(quán)限介紹”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI