一、添加用戶
新增用戶會有兩種方式的,一種是使用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"));
二、授權和取消授權
1、grant privileges on 數據庫名.表名 to '用戶名'@'登錄地址' identified by '密碼'; 2、grant select,insert on 數據庫名.表名 to '用戶名'@'登錄地址' identified by '密碼'; 3、grant all on *.* to '用戶名'@'登錄地址' identified by '密碼'; 4、grant all on 數據庫名.* to '用戶名'@'登錄地址' identified by '密碼'; --讓用戶 擁有授權 權限 5、grant privileges on 數據庫名.* to '用戶名'@'登錄地址' with grant option; --取消授權 6、revoke all on *.* from '用戶名'@'登錄地址';
三、查看用戶信息
當然有查看全部的用戶信息和單個的用戶信息
1、select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user; 2、select * from mysql.user where user='用戶名'; 3、show grants for '用戶名'@'登錄地址(%表示遠程登錄)'; --查看當前用戶的權限 4、show grants; --查看用戶表的結構 5、show mysql.user
四、修改用戶和刪除用戶
--修改用戶密碼 1、set password for 'username'@'host' = password('newpassword'); --當前用戶修改自己密碼 2、set password = passw ("newpassword"); --使用update 更新用戶 3、update user set password=password('123') where user='root' and host='localhost'; flush privileges; --刪除用戶 4、delete 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;