切換到mysql庫
use mysql
添加用戶
//允許指定ip連接
create user '用戶名'@'localhost' identified by '密碼';
//允許所有ip連接(%表示所有ip)
create user 'demo'@'%' identified by 'demo';
授權
grant all privileges on 數據庫名.表名 to '用戶名'@'指定ip' identified by '密碼' ;
// *表示所有
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
設置操作權限
// 設置所有權限
grant all privileges on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 設置select權限
grant select on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 其他權限: select, insert, delete, update用都好隔開
grant select,insert on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 取消用戶select權限
REVOKE select ON what FROM '用戶名';
刪除用戶
DROP USER username@localhost;
修改後刷新
FLUSH PRIVILEGES;