供cn2香港服務(wù)器參考MySQL數(shù)據(jù)庫權(quán)限管理

供cn2香港服務(wù)器參考MySQL數(shù)據(jù)庫權(quán)限管理

創(chuàng)新互聯(lián)專注于黃島網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供黃島營銷型網(wǎng)站建設(shè),黃島網(wǎng)站制作、黃島網(wǎng)頁設(shè)計、黃島網(wǎng)站官網(wǎng)定制、小程序設(shè)計服務(wù),打造黃島網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供黃島網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

cn2香港服務(wù)器MySQL權(quán)限表

MySQL數(shù)據(jù)庫實際上是通過將用戶寫入mysql庫中對應(yīng)的權(quán)限表來控制訪問權(quán)限的。
權(quán)限表分別為: user,db,table_priv,columns_priv和host。
user:記錄允許連接到服務(wù)器的用戶的信息,里面的權(quán)限是全局級的
db:記錄每個用戶對各個數(shù)據(jù)庫級別的操作權(quán)限
table_priv:記錄每個用戶對數(shù)據(jù)表級別的操作權(quán)限
columns_priv:記錄每個用戶對數(shù)據(jù)列級別的操作權(quán)限
host:存儲了某個主機對數(shù)據(jù)庫的操作權(quán)限,配合db表對給定的主機上數(shù)據(jù)庫級別的操作權(quán)限做更細致的控制,但host表一般很少用,新版本MySQL已經(jīng)沒有host表了
————————————————


cn2香港服務(wù)器MySQL數(shù)據(jù)庫權(quán)限命令格式

注意:sql語句大小皆可,看個人的使用習(xí)慣
關(guān)于數(shù)據(jù)庫的權(quán)限管理是通過對用戶的權(quán)限的設(shè)置來完成的
MySQL創(chuàng)建用戶的基礎(chǔ)格式:
在對權(quán)限的管理時,通常的寫法是創(chuàng)建用戶并授權(quán),不會先創(chuàng)建一個用戶再進行賦權(quán),通常使用的是下方第兩種格式的命令。
MySQL創(chuàng)建用戶的格式為:
create user 用戶名 identified by '該用戶密碼';
MySQL賦權(quán)的基礎(chǔ)格式為:
grant 權(quán)限 on 授權(quán)對象(庫.表) to 用戶@地址段 identified by "該用戶的密碼";
MySQL撤銷權(quán)限的基礎(chǔ)格式為:
revoke 撤銷相應(yīng)的權(quán)限時,正好與授權(quán)相反。
只要把該授權(quán)語句的"grant"改為"revoke", “to"改為"from”
revoke 權(quán)限 on 授權(quán)對象(庫.表) from 用戶@地址段 identified by "該用戶的密碼";
MySQL數(shù)據(jù)庫權(quán)限示例及解析
【1】授予的權(quán)限
all privileges 除with grant option(讓授權(quán)的用戶,也可以將這些權(quán)限 grant 給其他用戶,權(quán)限復(fù)制)之外的所有權(quán)限
alter 對數(shù)據(jù)表的修改的權(quán)限
alter routine 更改或者刪除存儲函數(shù)或者存儲過程的權(quán)限
create 創(chuàng)建數(shù)據(jù)庫及表的權(quán)限
create routine 更改和棄用存儲過程的能力
create temporary tables 創(chuàng)建臨時表的權(quán)限
create user 創(chuàng)建、重命名和撤銷用戶的權(quán)限
create view 創(chuàng)建視圖的權(quán)限
delete 數(shù)據(jù)表中刪除數(shù)據(jù)的權(quán)限
drop 允許刪除數(shù)據(jù)庫、表、視圖的權(quán)限
execute 執(zhí)行存儲過程或者調(diào)用函數(shù)的權(quán)限
event 允許查詢,創(chuàng)建,修改,刪除MySQL事件的權(quán)限
file 對系統(tǒng)中的文件(本地文件)讀取和寫操作的權(quán)限;
grant option 用戶委派權(quán)限的權(quán)限
index 創(chuàng)建、刪除索引的權(quán)限
insert 向表中插入數(shù)據(jù)的權(quán)限
lock tables 允許對擁有select權(quán)限的表進行鎖表的權(quán)限
process 查看所有用戶線程/連接的權(quán)限
references 5.7.6版本后,允許是否創(chuàng)建外鍵的權(quán)限
reload 允許執(zhí)行flush,重新加載權(quán)限表的權(quán)限
replication client 允許用戶查詢從服務(wù)器和主服務(wù)器位置的權(quán)限
replication slave 允許slave主機通過此用戶連接master建立主從的權(quán)限
select 允許從表中查看數(shù)據(jù)的權(quán)限
show databases 查看所有數(shù)據(jù)庫名的權(quán)限
show view 查看視圖詳細信息的權(quán)限
shutdown 允許關(guān)閉數(shù)據(jù)庫實例的權(quán)限
super 允許執(zhí)行一系列數(shù)據(jù)庫管理命令的權(quán)限(change、master、kill thread、mysqladmindebug、purge master logs、set global...)
trigger MySQL5.1.6后,允許創(chuàng)建,刪除,執(zhí)行,顯示觸發(fā)器的權(quán)限
update 允許修改表中的數(shù)據(jù)的權(quán)限
usage 創(chuàng)建一個用戶之后的默認權(quán)限,只代表連接,無其他任何權(quán)限
【2】MySQL數(shù)據(jù)庫授權(quán)注意事項
注意1:
grant select on 數(shù)據(jù)庫.數(shù)據(jù)表* to 用戶@'%' identified by "密碼" with grant option;
with grant option 是讓該授權(quán)的用戶,也可以將它的權(quán)限賦予給其他用戶
此種授權(quán)方法并不提倡,且實際上很少甚至幾乎不用。應(yīng)為權(quán)限最好是在DBA的手中,為了安全及方便管理
注意2:
grant 可以作用在單個數(shù)據(jù)庫及單個數(shù)據(jù)表上
被授權(quán)的范圍的寫法
*.* 意為所有的數(shù)據(jù)庫及表
數(shù)據(jù)庫名.* 意為該數(shù)據(jù)庫下的所有表
數(shù)據(jù)庫名.數(shù)據(jù)表名 意為該數(shù)據(jù)庫下的該數(shù)據(jù)表
注意3:
被授權(quán)的用戶的寫法
%代替一整個網(wǎng)段
'用戶名'@'%' 意為所有網(wǎng)段都可以用該用戶登陸數(shù)據(jù)庫
'用戶名'@'192.168.123.234' 意為只有此IP可使用該用戶登陸數(shù)據(jù)庫
'用戶名'@'192.168.122.%' 意為192.168.122該網(wǎng)段的所有主機都可使用該用戶登陸數(shù)據(jù)庫
【3】數(shù)據(jù)庫授權(quán)
<1>創(chuàng)建用戶并授予只讀權(quán)限
grant select on 數(shù)據(jù)庫名.* to 用戶@'%' identified by "密碼";
<2>創(chuàng)建用戶并授予插入數(shù)據(jù)權(quán)限
grant insert on 數(shù)據(jù)庫名.* to 用戶@'%' identified by "密碼";
<3>創(chuàng)建用戶并授予改變原有數(shù)據(jù)的權(quán)限
grant update on 數(shù)據(jù)庫名.* to 用戶@'%' identified by "密碼";
<4>創(chuàng)建用戶并授予刪除數(shù)據(jù)的權(quán)限
grant delete on 數(shù)據(jù)庫名.* to 用戶@'%' identified by "密碼";
要擁有以上所有權(quán)限,可寫為一條,權(quán)限間用“,”逗號隔開。
grant select, insert, update, delete on 數(shù)據(jù)庫名.* to 用戶@'%' identified by "密碼";
<5>創(chuàng)建用戶并授予所有權(quán)限
grant all privileges on 數(shù)據(jù)庫名.數(shù)據(jù)表明 to 用戶@'網(wǎng)段或ip' identified by "密碼" ;
<6>創(chuàng)建用戶并授予其對數(shù)據(jù)表的創(chuàng)建的權(quán)限
grant create on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<7>創(chuàng)建用戶并授予其對數(shù)據(jù)表的修改權(quán)限
grant alter on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<8>創(chuàng)建用戶并授予其對數(shù)據(jù)庫/表/視圖的刪除的權(quán)限
grant drop on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<9>創(chuàng)建用戶并授予其對數(shù)據(jù)庫下表的設(shè)置外鍵的權(quán)限
grant references on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<10>創(chuàng)建用戶并授予其對數(shù)據(jù)庫的設(shè)置臨時表權(quán)限
grant create temporary tables on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段/IP’ identified by '密碼';
<11>創(chuàng)建用戶并授予其對某數(shù)據(jù)庫范圍的表設(shè)置索引的權(quán)限
grant index on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<12>創(chuàng)建用戶并授予其對某數(shù)據(jù)庫范圍內(nèi)創(chuàng)建視圖的權(quán)限
grant create view on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’ identified by '密碼';
<13>創(chuàng)建用戶并授予其對某數(shù)據(jù)庫范圍內(nèi)查看視圖的權(quán)限
grant show view on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段/IP’ identified by '密碼';
<14>創(chuàng)建用戶并授予其對某數(shù)據(jù)庫范圍內(nèi)存儲過程、函數(shù)的權(quán)限
grant create routine on 數(shù)據(jù)庫名.* to 用戶@‘網(wǎng)段或IP’; -- now, can show procedure status
grant alter routine on 數(shù)據(jù)庫名.* to 用戶@'網(wǎng)段或IP'; -- now, you can drop a procedure
grant execute on 數(shù)據(jù)庫名.* to 用戶@'網(wǎng)段或IP';
<15>創(chuàng)建用戶并授予其對數(shù)據(jù)表中列的權(quán)限
如有很多列,要用逗號隔
grant select(列的名字) on 數(shù)據(jù)庫.數(shù)據(jù)表 to 用戶@‘網(wǎng)段或ip’ identified by ‘密碼';
<16>創(chuàng)建用戶并授予對數(shù)據(jù)表中的存儲過程和函數(shù)的權(quán)限
grant execute on procedure 數(shù)據(jù)庫名.數(shù)據(jù)表名 to '用戶'@'網(wǎng)段或IP' identified by '密碼';
grant execute on function 數(shù)據(jù)庫名.數(shù)據(jù)表名 to '用戶'@'網(wǎng)段或IP' identified by '密碼'
————————————————


創(chuàng)新互聯(lián)cn2香港服務(wù)器 E5 16G 240G SSD 1IP 5M 450元/月 特價中
cn2香港服務(wù)器美國站群服務(wù)器 美國高防御服務(wù)器 歡迎在線客服 QQ 4001886560 482986990

標(biāo)題名稱:供cn2香港服務(wù)器參考MySQL數(shù)據(jù)庫權(quán)限管理
新聞來源:http://www.muchs.cn/article26/dijg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、移動網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、商城網(wǎng)站、全網(wǎng)營銷推廣、網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)