1. 程式人生 > >Mysql新增使用者,訪問指定資料庫

Mysql新增使用者,訪問指定資料庫

1、使用root登入資料庫

mysql -uroot -p123456;

2、建立新使用者

create user 'admin'@'%' identified by 'Test123?';

注:

'%' - 所有情況都能訪問
‘localhost’ - 本機才能訪問
’111.222.33.44‘ - 指定 ip 才能訪問

修改密碼:

update mysql.user set password='新密碼' where user='user1';

3、給使用者新增訪問許可權

grant all privileges on 想授權的資料庫.* to 'admin'@'%';

all 可以替換為 select,delete,update,create,drop

4、重新整理許可權

flush privileges;

5、刪除使用者

Delete FROM mysql.user Where user='user1';