1、創建新用戶:
create user mark@localhost identified by '123456';
2、刪除用戶:
drop user mark@localhost;
3、修改用戶名:
rename user mark@localhost to mark1@localhost;
4、修改用戶密碼:
set password for mark@localhost = password('111111');
5、授予權限:
(1)授予表權限:select,insert,delete,update,references,create,alter,index,drop,all或者all privileges.
use mysql;
grant select on user to mark@localhost;
(2)授予數據庫權 限:select,insert,delete,update,references,create,alter,index,drop,create temporary tables,create view,show view,create routine,alter routine,execute routine,lock tables,all或者all privileges.
grant select on mysql.* to mark@localhost;
(3)授予用戶權限:create user,show databases
grant create user on *.* to mark@localhost;
grant create,alter,drop on *.* to mark@localhost;
6、權限的轉移和限制
(1)grant語句最後加with grant option,表示該用戶有把自己的權限授予其它用戶的權利,而不管其它用戶是否有該權限。
grant select on mysql.user to mark@localhost with grant option;
重新用mark登錄數據庫後,mark可以授予別的用戶相同的權限。
(2)with子句也可以對一個用戶授予實用限制。
max_queries_per_hour 1 每小時查詢數據庫次數為1。
max_connections_per_hour 1 每小時可以連接數據庫次數。
max_updates_per_hour 1 每小時可以修改數據庫次數
max_user_connections 1 同時連接mysql的最大用戶數。
如:
grant select on mysql.user to mark@localhost with max_queries_per_hour 1;
7、回收權限。
revoke select on mysql.user from mark@localhost;