MySQL用户远程访问授权

2023-05-26 11:00:01 买帖  | 投诉/举报

篇首语:本文由小编为大家整理,主要介绍了MySQL用户远程访问授权相关的知识,希望对你有一定的参考价值。

经常会出现数据库搭建在云端的ECS上,需要在本地IDE中进行开发和调试,记录一下mysql中的相关操作。

核心

  1. SSH 连接到服务器。
  2. 使用root用户登入MySQL。
  3. 对名为mysql的数据库进行操作,创建用户与用户权限。
[root@iZ28lvy05nsZ ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \\g.mysql> use mysqlDatabase changedmysql> create user 'test2020'@'%' identified by 'd029DB652b8';Query OK, 0 rows affected (0.00 sec)mysql> grant all privileges  on db2020.* to "test2020"@'%';Query OK, 0 rows affected (0.00 sec)

扩展

  1. 关于用户的操作
create user 'username'@'IP' identified by 'password';-- 单IPcreate user 'username'@'192.168.1.100' identified by 'password';-- IP段create user 'username'@'192.168.1.%' identified by 'password';-- 所有IPcreate user 'username'@'%' identified by 'password';
  1. 关于权限的操作
-- 查看权限show grants for 'username'@'IP'-- 授权grant 权限 on 数据库.表名 to "用户名"@'IP';-- 授权 test2020 用户仅对db2020.code表有查询、插入和更新的操作grant select ,insert,update on db2020.code to "test2020"@'%';-- 授权 test2020 用户对db2020下所有表有所有权限的操作grant all privileges  on db2020.* to "test2020"@'%';-- 授权 test2020 用户对所有库所有表有所有权限的操作grant all privileges  on *.*  to "test2020"@'%'; -- 取消授权revoke all privileges on *.* from 'test2020'@'%';

以上是关于MySQL用户远程访问授权的主要内容,如果未能解决你的问题,请参考以下文章