?
This document uses PHP Chinese website manual Release
grant命令簡(jiǎn)單語法
grant all privileges on dbname.* to username@localhost identified by ‘password’; # 創(chuàng)建用戶并授權(quán)
列表說明參數(shù):
grant | all privileges | on dbname.* | to username@localhost | identified by ‘password’ |
---|---|---|---|---|
授權(quán)命令 | 對(duì)應(yīng)權(quán)限 | 目標(biāo):庫(kù)和表 | 用戶名和客戶端主機(jī) | 用戶密碼 |
說明:上述命令是授權(quán)l(xiāng)ocalhost主機(jī)上通過username管理dbname數(shù)據(jù)庫(kù)的所有權(quán)限,密碼為password。其中username,dbname,password根據(jù)業(yè)務(wù)情況自行修改。
create和grant配合方法創(chuàng)建用戶并授權(quán)
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; # 創(chuàng)建用戶 grant all privileges on test.* to 'jeffrey'@'localhost'; # 給用戶授權(quán) show grants for 'jeffrey'@'localhost'; # 查看用戶權(quán)限明細(xì)
授權(quán)局域網(wǎng)內(nèi)主機(jī)遠(yuǎn)程連接數(shù)據(jù)庫(kù):
根據(jù)grant命令語法,我們知道'jeffrey'@'localhost'位置為授權(quán)訪問數(shù)據(jù)庫(kù)的主機(jī),localhost可以使用域名,IP地址或者IP段來替代,因此,要授權(quán)局域網(wǎng)內(nèi)主機(jī)可以通過如下方法實(shí)現(xiàn):
grant all on *.* to username@'192.168.1.%' identified by 'password'; # 百分號(hào)匹配 grant all on *.* to username@'192.168.1.0/255.255.255.0' identified by 'password'; # 子網(wǎng)掩碼配置
刪除MySQL用戶
DROP USER 'jeffrey'@'localhost';
insert, select, update, delete, create, drop, references, index, alter, create temporary tables, lock tables, execute, create view, show view, create routine, alter routine, event, trigger
grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES, REPLICATION CLIENT, EVENT,TRIGGER ON *.* TO 'back_user'@'Host' IDENTIFIED BY 'Password'; flush privileges;
權(quán)限列表
SELECT 讀取
SHOW DATABASES 允許訪問完整的數(shù)據(jù)庫(kù)列表
LOCK TABLES 允許鎖定表
RELOAD 允許載入和刷新服務(wù)器緩存
REPLICATION CLIENT 允許用戶詢問從屬服務(wù)器或主服務(wù)器的地址
EVENT 允許執(zhí)行事務(wù)
TRIGGER 觸發(fā)器相關(guān)的權(quán)限