搬運出處: https://www.cnblogs.com/wuxunyan/p/9095016.html
1. 新建用戶
格式:create user "username"@"host" identified by "password";
host="localhost" 允許本地登錄,host="ip" 允許ip地址,host="%",允許所以ip登錄
mysql->create user 'test'@'localhost' identified by '123456'; mysql->create user 'test'@'192.168.1.11' identified by '123456';
mysql->create user 'test'@'%' identified by '123456';
2. 刪除用戶
格式:drop user 'username'@'host';
(5)授權
格式:grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';
/*授予用戶通過外網IP對於該數據庫的全部權限*/ grant all privileges on `test`.* to 'test'@'%' ; /*授予用戶在本地服務器對該數據庫的全部權限*/ grant all privileges on `test`.* to 'test'@'localhost'; grant select on test.* to 'user1'@'localhost'; /*給予查詢權限*/ grant insert on test.* to 'user1'@'localhost'; /*添加插入權限*/ grant delete on test.* to 'user1'@'localhost'; /*添加刪除權限*/ grant update on test.* to 'user1'@'localhost'; /*添加權限*/ flush privileges; /*刷新權限*/
/*授予用戶通過外網IP對於該數據庫的全部權限*/
grant all privileges on `test`.* to 'test'@'%' ;
/*授予用戶在本地服務器對該數據庫的全部權限*/
grant all privileges on `test`.* to 'test'@'localhost';
grant select on test.* to 'user1'@'localhost'; /*給予查詢權限*/
grant insert on test.* to 'user1'@'localhost'; /*添加插入權限*/
grant delete on test.* to 'user1'@'localhost'; /*添加刪除權限*/
grant update on test.* to 'user1'@'localhost'; /*添加權限*/
flush privileges; /*刷新權限*/
