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;
