mysql5.7 為用戶授權


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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM