MySQL用戶權(quán)限設(shè)置保護(hù)數(shù)據(jù)庫安全
更改mysql密碼
-- 查詢用戶權(quán)限 show grants for 'root'@'%'; update mysql.user set authentication_string=password('密碼') where user='root' and Host = 'localhost'; flush privileges; -- 或者下面方式 alter user 'test1'@'localhost' identified by '新密碼'; flush privileges;
創(chuàng)建用戶
-- 創(chuàng)建本地的 -- create user 'test1'@'localhost' identified by '密碼'; -- 創(chuàng)建可以遠(yuǎn)程訪問的 create user 'wjl'@'%' identified by 'wujialiang';
給用戶所有權(quán)限
-- grant all privileges on *.* to 'wjl'@'localhost' with grant option; grant all privileges on *.* to 'wjl'@'%' with grant option;
第一個(gè)表示通配數(shù)據(jù)庫,可指定新建用戶只可操作的數(shù)據(jù)庫
如:grant all privileges on 數(shù)據(jù)庫. to ‘test1’@‘localhost’;
第二個(gè)*表示通配表,可指定新建用戶只可操作的數(shù)據(jù)庫下的某個(gè)表
如:grant all privileges on 數(shù)據(jù)庫.指定表名 to ‘test1’@‘localhost’;
all privileges 可換成select,update,insert,delete,drop,create等操作 如:grant select,insert,update,delete on . to ‘test1’@‘localhost’;
移除用戶所有權(quán)限
-- revoke all privileges on *.* from 'wjl'@'localhost'; revoke all privileges on *.* from 'wjl'@'%';
添加部分權(quán)限
-- GRANT Select,Update,insert,delete ON *.* TO '用戶名'@"%"; GRANT select,update,insert,delete ON *.* TO 'wjl'@"%";
移除部分權(quán)限
-- REVOKE select,insert ON 數(shù)據(jù)庫.* FROM wjl@'localhost' REVOKE select,insert ON 數(shù)據(jù)庫.* FROM wjl@'%'
刪除用戶
drop user 'wjl'@'localhost';
權(quán)限解釋
參數(shù) | 解釋 |
---|---|
?All/All Privileges | 代表全局或者全數(shù)據(jù)庫對(duì)象級(jí)別的所有權(quán)限?? |
Alter | 代表允許修改表結(jié)構(gòu)的權(quán)限,但必須要求有create和insert權(quán)限配合。如果是rename表名,則要求有alter和drop原表, create和insert新表的權(quán)限 |
Alter routine | 代表允許修改或者刪除存儲(chǔ)過程、函數(shù)的權(quán)限 |
Create | 代表允許創(chuàng)建新的數(shù)據(jù)庫和表的權(quán)限 |
Create routine | 代表允許創(chuàng)建存儲(chǔ)過程、函數(shù)的權(quán)限 |
Create tablespace | 代表允許創(chuàng)建、修改、刪除表空間和日志組的權(quán)限 |
Create temporary tables | 代表允許創(chuàng)建臨時(shí)表的權(quán)限 |
Create user | 代表允許創(chuàng)建、修改、刪除、重命名user的權(quán)限 |
Create view | 代表允許創(chuàng)建視圖的權(quán)限 |
Delete | 代表允許刪除行數(shù)據(jù)的權(quán)限 |
Drop | 代表允許刪除數(shù)據(jù)庫、表、視圖的權(quán)限,包括truncate table命令 |
Event | 代表允許查詢,創(chuàng)建,修改,刪除MySQL事件 |
Execute | 代表允許執(zhí)行存儲(chǔ)過程和函數(shù)的權(quán)限 |
File | 代表允許在MySQL可以訪問的目錄進(jìn)行讀寫磁盤文件操作,可使用的命令包括load data infile,select … into outfile,load file()函數(shù) |
Grant option | 權(quán)限代表是否允許此用戶授權(quán)或者收回給其他用戶你給予的權(quán)限,重新付給管理員的時(shí)候需要加上這個(gè)權(quán)限 |
Index | 代表是否允許創(chuàng)建和刪除索引 |
Insert | 代表是否允許在表里插入數(shù)據(jù),同時(shí)在執(zhí)行analyze table,optimize table,repair table語句的時(shí)候也需要insert權(quán)限 |
Lock | 代表允許對(duì)擁有select權(quán)限的表進(jìn)行鎖定,以防止其他鏈接對(duì)此表的讀或?qū)?/td> |
Process | 代表允許查看MySQL中的進(jìn)程信息,比如執(zhí)行show processlist, mysqladmin processlist, show engine等命令 |
Reference | 是在5.7.6版本之后引入,代表是否允許創(chuàng)建外鍵 |
Reload | 代表允許執(zhí)行flush命令,指明重新加載權(quán)限表到系統(tǒng)內(nèi)存中,refresh命令代表關(guān)閉和重新開啟日志文件并刷新所有的表 |
Replication client | 代表允許執(zhí)行show master status,show slave status,show binary logs命令 |
Replication slave | 代表允許slave主機(jī)通過此用戶連接master以便建立主從復(fù)制關(guān)系 |
Select | 代表允許從表中查看數(shù)據(jù),某些不查詢表數(shù)據(jù)的select執(zhí)行則不需要此權(quán)限,如Select 1+1, Select PI()+2;而且select權(quán)限在執(zhí)行update/delete語句中含有where條件的情況下也是需要的 |
Show databases | 代表通過執(zhí)行show databases命令查看所有的數(shù)據(jù)庫名 |
Show view | 代表通過執(zhí)行show create view命令查看視圖創(chuàng)建的語句 |
Shutdown | 代表允許關(guān)閉數(shù)據(jù)庫實(shí)例,執(zhí)行語句包括mysql admin shutdown |
Super | 代表允許執(zhí)行一系列數(shù)據(jù)庫管理命令,包括kill強(qiáng)制關(guān)閉某個(gè)連接命令, change master to創(chuàng)建復(fù)制關(guān)系命令,以及create/alter/drop server等命令 |
Trigger | 代表允許創(chuàng)建,刪除,執(zhí)行,顯示觸發(fā)器的權(quán)限 |
Update | 代表允許修改表中的數(shù)據(jù)的權(quán)限 |
Usage | 是創(chuàng)建一個(gè)用戶之后的默認(rèn)權(quán)限,其本身代表連接登錄權(quán)限 |
案例
普通用戶權(quán)限
grant all privileges on *.* to 'wjl'@'%' with grant option; REVOKE Shutdown,Process,Grant option,Drop ON *.* FROM wjl@'%'; flush privileges;
到此這篇關(guān)于MySQL用戶權(quán)限設(shè)置保護(hù)數(shù)據(jù)庫安全的文章就介紹到這了,更多相關(guān)MySQL用戶權(quán)限設(shè)置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MySQL學(xué)習(xí)筆記之?dāng)?shù)據(jù)的增、刪、改實(shí)現(xiàn)方法
這篇文章主要介紹了MySQL學(xué)習(xí)筆記之?dāng)?shù)據(jù)的增、刪、改實(shí)現(xiàn)方法,簡(jiǎn)單介紹了mysql實(shí)現(xiàn)數(shù)據(jù)的增、刪、改相關(guān)語法與使用技巧,需要的朋友可以參考下2016-09-09MySQL架構(gòu)體系知識(shí)點(diǎn)總結(jié)
在本篇內(nèi)容里我們給大家整理了關(guān)于MySQL架構(gòu)體系的相關(guān)知識(shí)點(diǎn)內(nèi)容以及相關(guān)實(shí)例,需要的朋友們學(xué)習(xí)下。2019-02-02