1. 程式人生 > >mysql5.7+修改使用者的密碼和給使用者授權

mysql5.7+修改使用者的密碼和給使用者授權

一、修改密碼

mysql -u root -p 

update mysql.user setauthentication_string=password(“新密碼”) where User="test" and Host="localhost"; 

flush privileges;

mysql5.7以後mysql.user表中沒有了password欄位,而是使用authentication_string來代替。

二、刪除使用者

mysql -u root -p 

Delete FROM mysql.user Where User="使用者名稱" and Host="localhost"; 

flush privileges; 

建立使用者

命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';

刪除賬戶及許可權:

drop user 使用者名稱@’%’;

drop user 使用者名稱@ localhost;

三、為使用者授權

授權格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by “密碼”;

eg: grant all privileges on *.* to 'root'@'192.168.218.128' identified by 'hello' with grant option;//賦予使用者所有資料庫的許可權以及建立資料庫的許可權

flush privileges; //要重新整理許可權

授權test使用者擁有testDB資料庫的所有許可權:

grant all privileges on testDB.* to "test"@"localhost" identified by "1234"; 
flush privileges; #刷新系統許可權表

指定部分許可權給使用者:

grant select,update on testDB.* to "test"@"localhost" identified by "1234"; 
flush privileges; #刷新系統許可權表

四、顯示當前使用者資訊

select user();