use mysql;
create user 'demo'@'%' identified by 'demo';
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
grant all privileges on *.* to 'demo'@'%' identified by 'demo' WITH GRANT OPTION;
FLUSH PRIVILEGES;
分解步驟
首先:切換到mysql庫
use mysql;
添加用戶
//允許指定ip連接
create user '用戶名'@'localhost' identified by '密碼';
//允許所有ip連接(%表示所有ip)
create user 'demo'@'%' identified by 'demo';
授權(quán)
grant all privileges on 數(shù)據(jù)庫名.表名 to '用戶名'@'指定ip' identified by '密碼' ;
// *表示所有
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;
設(shè)置操作權(quán)限
// 設(shè)置所有權(quán)限
grant all privileges on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 設(shè)置select權(quán)限
grant select on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 其他權(quán)限: select, insert, delete, update用都好隔開
grant select,insert on *.* to '用戶名'@'指定ip' identified by '密碼' WITH GRANT OPTION;
// 取消用戶select權(quán)限
REVOKE select ON what FROM '用戶名';