ubuntu下mysql的用戶添加、授權、取消授權


一、添加用戶

新增用戶會有兩種方式的,一種是使用create命令,另一種是直接回使用grant 命令

create user 名字@登陸地址 identified by "密碼";

grant select,update(權限) on 數據庫名.表名 to 用戶@登錄地址 identified by '密碼';
 
insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

二、授權和取消授權

 

1grant privileges on 數據庫名.表名 to '用戶名'@'登錄地址' identified by '密碼';
 
2grant select,insert on 數據庫名.表名 to '用戶名'@'登錄地址' identified by '密碼';
 
3grant all on *.* to '用戶名'@'登錄地址' identified by '密碼';
 
4grant all on 數據庫名.* to '用戶名'@'登錄地址' identified by '密碼';
 
--讓用戶 擁有授權 權限
5grant privileges on  數據庫名.* to '用戶名'@'登錄地址' with grant option;
 
--取消授權
6revoke all on *.* from '用戶名'@'登錄地址';

三、查看用戶信息

 

當然有查看全部的用戶信息和單個的用戶信息

1select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;
 
2select * from mysql.user where user='用戶名';
 
3、show grants for '用戶名'@'登錄地址(%表示遠程登錄)';
--查看當前用戶的權限
4、show grants; 
 
--查看用戶表的結構
5、show mysql.user

四、修改用戶和刪除用戶

--修改用戶密碼
1set password for 'username'@'host' = password('newpassword');
 
--當前用戶修改自己密碼
2set password = passw ("newpassword");
 
--使用update 更新用戶
3update user set password=password('123') where user='root' and host='localhost'; 
   flush privileges; 
 
--刪除用戶 
4delete from mysql.user where user='root' and host='%';
   flush privileges;
————————————————
版權聲明:本文為CSDN博主「每天加點分」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/lcf_lxf_ldy/article/details/87721073

如果操作沒生效請執行

flush privileges;

 






免責聲明!

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



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