MYSQL8用戶創建及權限操作


MYSQL8創建、刪除用戶和授權、消權操作

 

上網找過資料說要進入mysql數據庫在進行這些操作,我試了發現不進數據庫和進入mysql數據庫效果都一樣

 

網上有的直接創建並賦權,像醬紫的:

grant all privileges *.* to '要創建的用戶'@'localhost' identified by '自定義密碼';

我在mysql8試了不行(8版本以下還沒試過),要先創建用戶再進行賦權,不能同時進行

 

創建用戶

create user 'test1'@'localhost' identified by '‘密碼';

flush privileges;刷新權限

 

其中localhost指本地才可連接

可以將其換成%指任意ip都能連接

也可以指定ip連接

 

修改密碼

Alter user 'test1'@'localhost' identified by '新密碼';

flush privileges;

 

授權

grant all privileges on *.* to 'test1'@'localhost' with grant option;

 

with gran option表示該用戶可給其它用戶賦予權限,但不可能超過該用戶已有的權限

比如a用戶有select,insert權限,也可給其它用戶賦權,但它不可能給其它用戶賦delete權限,除了select,insert以外的都不能

這句話可加可不加,視情況而定。

 

all privileges 可換成select,update,insert,delete,drop,create等操作

如:grant select,insert,update,delete on *.* to 'test1'@'localhost';

 

第一個*表示通配數據庫,可指定新建用戶只可操作的數據庫

如:grant all privileges on 數據庫.* to 'test1'@'localhost';

 

第二個*表示通配表,可指定新建用戶只可操作的數據庫下的某個表

如:grant all privileges on 數據庫.指定表名 to 'test1'@'localhost';

 

 

查看用戶授權信息

show grants for 'test1'@'localhost';

 

 

撤銷權限

revoke all privileges on *.* from 'test1'@'localhost';

用戶有什么權限就撤什么權限

 

刪除用戶

drop user 'test1'@'localhost';

 


免責聲明!

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



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