Linux下,MySQL新建用戶、數(shù)據(jù)庫(kù)并授權(quán)

Linux下,MySQL新建用戶、數(shù)據(jù)庫(kù)并授權(quán)

1、新建用戶

//創(chuàng)建用戶

mysql>use mysql

insert into user(Host,User,Password) values ('localhost','Barry',password('123456'));

//刷新系統(tǒng)權(quán)限表

mysql>flush privileges;

這樣就創(chuàng)建了一個(gè)用戶:Barry,密碼是:123456


2、登錄測(cè)試

mysql>exit;

# mysql -uroot -p

密碼輸入:123456


3、用戶授權(quán)

//為用戶創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)(barry_data)

msyql>create database barry_data;

//授權(quán)用戶Barry使用密碼123456擁有barry_data數(shù)據(jù)庫(kù)的所有權(quán)限,并從任何主機(jī)可以連接。

mysql>grant all privileges on barry_data.* to Barry@'%' identified by '123456' with grant obtion;


//如果想限制用戶只能從192.168.200.101的主機(jī)連接到mysql服務(wù)器,授權(quán)語(yǔ)句如下:

mysql>grant all privileges on?barry_data.* to Barry@'192.168.200.101' identified by '123456'


//部分授權(quán),語(yǔ)句如下:

mysql>grant select,update on barry_data.* to Barry@localhost identified by '123456';


//授予權(quán)限后,刷新系統(tǒng)權(quán)限表

mysql>flush privileges;

注意:with grant obtion?和 with admin obtion

with grant obtion:授予給A權(quán)限,A將權(quán)限授予B;revoke授予給A的權(quán)限時(shí),B的權(quán)限也會(huì)被級(jí)聯(lián)回收。

with admin obtion:授予給A權(quán)限,A將權(quán)限授予B;revoke授予給A的權(quán)限時(shí),B的權(quán)限不會(huì)被級(jí)聯(lián)回收。


4、刪除用戶

mysql>delete from user where user='Barry';

msyql>flush privileges;


5、刪除數(shù)據(jù)庫(kù)

mysql>drop databases barry_data;


6、修改密碼

mysql>use mysql

mysql>update user set password=password('新密碼') where User='Barry' and Host='localhost';

msyql>flush privileges;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容