MySQL用户远程访问授权

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

核心

  1. SSH 连接到服务器。
  2. 使用root用户登入MySQL。
  3. 对名为mysql的数据库进行操作,创建用户与用户权限。
[root@iZ28lvy05nsZ ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.


mysql> use mysql
Database changed


mysql> 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';

-- 单IP
create user 'username'@'192.168.1.100' identified by 'password';

-- IP段
create user 'username'@'192.168.1.%' identified by 'password';

-- 所有IP
create 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'@'%';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值