MySQL添加新用戶、爲用戶建立數據庫、爲新用戶分配權限

登陸MySQLmysql

mysql -u root -p

添加新用戶

容許本地 IP 訪問 localhost, 127.0.0.1sql

create user 'test'@'localhost' identified by '123456';

容許外網 IP 訪問數據庫

create user 'test'@'%' identified by '123456';

刷新受權服務器

flush privileges;

爲用戶建立數據庫

create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

爲新用戶分配權限

授予用戶經過外網IP對於該數據庫的所有權限ide

grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';

授予用戶在本地服務器對該數據庫的所有權限code

grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';

刷新權限ci

flush privileges;
相關文章
相關標籤/搜索