mysql【忘記root密碼】以及【創建新用戶】

切換到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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章