1、用戶不存在,授權數據庫權限的同時,並創建用戶。
# 授權,創建用戶,設置密碼 mysql> grant all on *.* to jhtest@'%' identified by '123456'; Query OK, 0 rows affected (0.01 sec)
2、為已存在的用戶授權,只需要把 identified by 'jhtest' 去掉。
MySQL grant 權限,分別可以作用在多個層次上。
grant 作用在整個 MySQL 服務器上:
grant select on *.* to dba@localhost; # 可以查詢 MySQL 中所有數據庫中的表。 grant all on *.* to dba@localhost; # 可以管理 MySQL 中的所有數據庫 grant 作用在單個數據庫上: grant select on testdb.* to dba@localhost; # 可以查詢 testdb 中的表。 grant 作用在單個數據表上: grant select, insert, update, delete on testdb.orders to dba@localhost;
3、查看權限
查看當前用戶(自己)權限:
show grants; 查看其他 MySQL 用戶權限: show grants for dba@localhost;
4、撤銷已經賦予給 MySQL 用戶權限的權限。
revoke 跟 grant 的語法差不多,只需要把關鍵字 “to” 換成 “from” 即可: grant all on *.* to dba@localhost; revoke all on *.* from dba@localhost;
