mysql授權以及權限管理


權限管理

 

1、創建用戶

create user '用戶名'@'IP地址' identified by '密碼';    # 語法
create user '用戶名'@'localhost' identified by '密碼';   # 本地可用賬號
create user '用戶名'@'192.168.12.1' identified by '密碼'; # 具體哪個ip可用賬號
create user '用戶名'@'192.168.12.%' identified by '密碼'; # 具體哪個網段可用賬號
create user '用戶名'@'%' identified by '密碼';      # 所有ip都可用賬號

2、刪除用戶

drop user '用戶名'@'IP地址';

3、修改用戶

rename user '用戶名'@'IP地址' to '新用戶名'@'IP地址';

4、修改密碼

set password for '用戶名'@'IP地址' = password('新密碼');

5、授權

grant 權限 on 數據庫.表 to '用戶'@'IP地址'    # 授權語法

grant select on db1.* to 'zekai'@'%';   # db1下所有表授予select權限
grant select on *.* to 'zekai'@'%';     # 所有數據庫都授予select權限
grant select,insert on *.* to 'zekai'@'%';  # 授予多個權限
grant all privileges on *.* to 'zekai'@'%';            # 授予全部權限,除了創建用戶

6、創建與授權聯合使用

grant all privileges on *.* to "賬號名"@"%" identified by "密碼" with grant option;

注意:

  每次授權完之后,一定要刷新授權

flush privileges;


免責聲明!

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



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