mysql用戶管理和權(quán)限設(shè)置的相關(guān)命令有哪些-創(chuàng)新互聯(lián)

這篇文章主要介紹了mysql 用戶管理和權(quán)限設(shè)置的相關(guān)命令有哪些,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的華池網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

MySQL是世界上最受歡迎的數(shù)據(jù)庫(kù)管理系統(tǒng)之一。書中從介紹簡(jiǎn)單的數(shù)據(jù)檢索開始,逐步深入一些復(fù)雜的內(nèi)容,包括聯(lián)結(jié)的使用、子查詢、正則表達(dá)式和基于全文本的搜索、存儲(chǔ)過程、游標(biāo)、觸發(fā)器、表約束,等等。通過重點(diǎn)突出的章節(jié),條理清晰、系統(tǒng)而扼要地講述了讀者應(yīng)該掌握的知識(shí),使他們不經(jīng)意間立刻功力大增。本節(jié)內(nèi)容主要講述了mysql 用戶管理和權(quán)限設(shè)置的相關(guān)命令整理。

用戶管理

mysql>use mysql;

查看

mysql>select host,user,password from user ;

創(chuàng)建

mysql>create user zx_root;

修改

mysql>rename user feng to newuser; //mysql 5之后可以使用,之前需要使用update 更新user表

刪除

mysql>drop user newuser;   //mysql5之前刪除用戶時(shí)必須先使用revoke 刪除用戶權(quán)限,然后刪除用戶,mysql5之后drop 命令可以刪除用戶的同時(shí)刪除用戶的相關(guān)權(quán)限

更改密碼

mysql>set password for zx_root =password('xxxxxx');
mysql>update  mysql.user  set  password=password('xxxx')  where user='otheruser'


查看用戶權(quán)限

mysql>show grants for zx_root;

賦予權(quán)限

mysql>grant select on dmc_db.*  to zx_root;

回收權(quán)限

mysql>revoke  select on dmc_db.*  from  zx_root;  //如果權(quán)限不存在會(huì)報(bào)錯(cuò)

上面的命令也可使用多個(gè)權(quán)限同時(shí)賦予和回收,權(quán)限之間使用逗號(hào)分隔

mysql>grant select,update,delete  ,insert  on dmc_db.*  to  zx_root;

如果想立即看到結(jié)果使用

flush  privileges ;

命令更新

設(shè)置權(quán)限時(shí)必須給出一下信息

1,要授予的權(quán)限

2,被授予訪問權(quán)限的數(shù)據(jù)庫(kù)或表

3,用戶名

grant和revoke可以在幾個(gè)層次上控制訪問權(quán)限

1,整個(gè)服務(wù)器,使用 grant ALL  和revoke  ALL

2,整個(gè)數(shù)據(jù)庫(kù),使用on  database.*

3,特點(diǎn)表,使用on  database.table

4,特定的列

5,特定的存儲(chǔ)過程

user表中host列的值的意義

%              匹配所有主機(jī)

localhost      localhost不會(huì)被解析成IP地址,直接通過UNIXsocket連接

127.0.0.1      會(huì)通過TCP/IP協(xié)議連接,并且只能在本機(jī)訪問

::1            ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1

grant 普通數(shù)據(jù)用戶,查詢、插入、更新、刪除 數(shù)據(jù)庫(kù)中所有表數(shù)據(jù)的權(quán)利。

grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@'%'
grant update on testdb.* to common_user@'%'
grant delete on testdb.* to common_user@'%'

或者,用一條 MySQL 命令來替代:

grant select, insert, update, delete on testdb.* to common_user@'%'

9>.grant 數(shù)據(jù)庫(kù)開發(fā)人員,創(chuàng)建表、索引、視圖、存儲(chǔ)過程、函數(shù)。。。等權(quán)限。

grant 創(chuàng)建、修改、刪除 MySQL 數(shù)據(jù)表結(jié)構(gòu)權(quán)限。

grant create on testdb.* to developer@'192.168.0.%';
grant alter on testdb.* to developer@'192.168.0.%';
grant drop on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 外鍵權(quán)限。

grant references on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 臨時(shí)表權(quán)限。

grant create temporary tables on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 索引權(quán)限。

grant index on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 視圖、查看視圖源代碼 權(quán)限。

grant create view on testdb.* to developer@'192.168.0.%';
grant show view on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 存儲(chǔ)過程、函數(shù) 權(quán)限。

grant create routine on testdb.* to developer@'192.168.0.%'; -- now, can show procedure status
grant alter routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a procedure
grant execute on testdb.* to developer@'192.168.0.%';

10>.grant 普通 DBA 管理某個(gè) MySQL 數(shù)據(jù)庫(kù)的權(quán)限。

grant all privileges on testdb to dba@'localhost'

其中,關(guān)鍵字 “privileges” 可以省略。

11>.grant 高級(jí) DBA 管理 MySQL 中所有數(shù)據(jù)庫(kù)的權(quán)限。

grant all on *.* to dba@'localhost'

12>.MySQL grant 權(quán)限,分別可以作用在多個(gè)層次上。

1. grant 作用在整個(gè) MySQL 服務(wù)器上:

grant select on *.* to dba@localhost; -- dba 可以查詢 MySQL 中所有數(shù)據(jù)庫(kù)中的表。
grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有數(shù)據(jù)庫(kù)

2. grant 作用在單個(gè)數(shù)據(jù)庫(kù)上:

grant select on testdb.* to dba@localhost; -- dba 可以查詢 testdb 中的表。

3. grant 作用在單個(gè)數(shù)據(jù)表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存儲(chǔ)過程、函數(shù)上:

grant execute on procedure testdb.pr_add to 'dba'@'localhost'
grant execute on function testdb.fn_add to 'dba'@'localhost'

注意:修改完權(quán)限以后 一定要刷新服務(wù),或者重啟服務(wù),刷新服務(wù)用:FLUSH PRIVILEGES。

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“mysql 用戶管理和權(quán)限設(shè)置的相關(guān)命令有哪些”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

當(dāng)前文章:mysql用戶管理和權(quán)限設(shè)置的相關(guān)命令有哪些-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://muchs.cn/article30/csjoso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)域名注冊(cè)、面包屑導(dǎo)航、外貿(mào)建站、建站公司、網(wǎng)站改版

廣告

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

商城網(wǎng)站建設(shè)