MySql 5.7中添加用戶,新建數據庫,用戶授權,刪除用戶,修改密碼


轉自http://blog.csdn.net/w690333243/article/details/76576952

配置root密碼

set password for root@localhost = password('123456');

1、新建用戶 
創建test用戶,密碼是1234。

MySQL -u root -p 
CREATE USER 'test'@'localhost'  IDENTIFIED BY '1234'; #本地登錄 
CREATE USER 'test'@'%'  IDENTIFIED BY '1234'; #遠程登錄 
quit 
mysql -u test -p #測試是否創建成功

2、為用戶授權

a.授權格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by '密碼'; 

b.登錄MYSQL,這里以ROOT身份登錄:

mysql -u root -p

c.為用戶創建一個數據庫(testDB):

create database testDB; 
create database testDB default charset utf8 collate utf8_general_ci;

d.授權test用戶擁有testDB數據庫的所有權限:

grant all privileges on testDB.* to “test”@”localhost” identified by “1234”; 
flush privileges; #刷新系統權限表

e.指定部分權限給用戶:

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

f.授權test用戶擁有所有數據庫的某些權限:  

grant select,delete,update,create,drop on . to test@”%” identified by “1234”; #”%” 表示對所有非本地主機授權,不包括localhost

3、刪除用戶

mysql -u root -p 
Delete FROM mysql.user Where User=”test” and Host=”localhost”; 
flush privileges; 
drop database testDB;

刪除賬戶及權限:

drop user 用戶名@’%’; 
drop user 用戶名@ localhost;

4、修改指定用戶密碼

mysql -u root -p 
update mysql.user set authentication_string=password(“新密碼”) where User=”test” and Host=”localhost”; 
flush privileges;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM