1. 程式人生 > >MySql 5.7中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼

MySql 5.7中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼

1、新建使用者
建立test使用者,密碼是1234。

mysql -u root -p
CREATE USER “test”@”localhost” IDENTIFIED BY “1234”; #本地登入
CREATE USER “test”@”%” IDENTIFIED BY “1234”; #遠端登入
quit
mysql -utest -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 [email protected]”%” 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;