mysql 允许远程登陆

很多时候,我们的数据库服务和应用并不在一台服务器上,所以要开启mysql远程登陆。网上这种教程很多,但是质量参差不齐,讲的不透彻。

mysql -V: mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper

图中所用连接工具为navicat。navicat能登录的话,shell也一样可以。

1. 新建非root、可远程登陆的用户


mysql> create user 'username'@'%' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on database.* to 'username'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
复制代码

有部分资料到这一步就已经结束了,此时尝试远程登陆,依然失败。

2. 修改mysqld.cnf中的bind-address

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
==>>
bind-address            = 0.0.0.0
复制代码

官方文档对于bind address的描述:
If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces. If the option specifies a list of multiple values, this value is not permitted.
查看详细文档

由此可见,此步的操作决定着第一步是否生效


此时就可以远程连接成功啦!

3. 安全加固

此时所有IPV4的主机都可以连接该SQL server,安全性相对较差。但是bind address只能指定一个IP,因此我们只能用防火墙来达到这个目的了,具体看mysql实现绑定多个ip


参考文章:

  1. Mysql创建新用户方法
  2. MySQL bind-address
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值