MySQL用户管理

首先使用root用户登录mysql(或者有操作权限的用户),然后切换到名称为mysql的数据库

> mysql -h192.168.1.1 -uroot -p123456
mysql> use mysql;

添加用户

mysql> create user test_user identified by '123456';

mysql> select host,user,password from user where user = 'test_user';
+------+-----------+-------------------------------------------+
| host | user      | password                                  |
+------+-----------+-------------------------------------------+
| %    | test_user | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+

用户授权

mysql> grant all privileges on *.* to test_user@'%' identified by '123456'; 
mysql> flush privileges;

# 如果需要指定限制访问的IP段,或者指定访问的数据库
mysql> grant all privileges on test_db.* to root@'10.20.30.%' identified by '123456';
mysql> flush privileges;

用户撤权,revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

mysql> revoke all on test_db.* from root@'10.20.30.%' identified by '123456';

修改密码

mysql> update mysql.user set password = password('654321') where user = 'test_user' and host = '%';
mysql> flush privileges;

删除用户

mysql> drop user test_user@'%';

欢迎订阅「K叔区块链」 – 专注于区块链技术学习

《MySQL用户管理》

博客地址:
http://www.jouypub.com

简书主页:
https://www.jianshu.com/u/756c9c8ae984

segmentfault主页:
https://segmentfault.com/blog/jouypub

腾讯云主页:
https://cloud.tencent.com/developer/column/72548

    原文作者:JouyPub
    原文地址: https://segmentfault.com/a/1190000015938949
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞