mysql新建用戶并分配管理指定的數(shù)據(jù)庫(kù)
1.首先創(chuàng)建用戶密碼:tom tompassword
>mysql -uroot -p 鍵入密碼登陸到root用戶
mysql>insert into
mysql.user(host,user,password) values(‘localhost’,’tom’,password(‘tompassword’)); #表中插入用戶
mysql>flush ppribileges; #刷新系統(tǒng)權(quán)限表
2.創(chuàng)建數(shù)據(jù)庫(kù):dbtom
mysql>create
database dbtom;
3.授權(quán)tom用戶擁有dbtom數(shù)據(jù)庫(kù)的所有權(quán)限
mysql>grant all privileges on tomdb.*
to tom@localhost identified by ‘tom’;
mysql>flush
privileges;
如果僅僅指定部分權(quán)限給tom用戶:
mysql>grant
select,update on dbtom.* to tom@localhost identified by ‘tom’;
mysql>flush
privileges;
4.這樣tom用戶就可以登陸到mysql中對(duì)dbtom數(shù)據(jù)庫(kù)進(jìn)行管理了,但是對(duì)其他數(shù)據(jù)庫(kù)沒有操作權(quán)限。
5.刪除用戶
mysql>delete
from user where user=”tom” and host=”localhost”;
mysql>flush
privileges;
6.刪除數(shù)據(jù)庫(kù)
mysql>drop
database tomdb;
7.修改tom用戶的密碼
mysql>update
mysql.user set password=password(‘新密碼’) where user=”tom”;
mysql>flush
privileges;
mysql>quit;