1

阿里云 | 让外界访问 mysql

 1 year ago
source link: https://benpaodewoniu.github.io/2022/05/26/aliyun1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

让外界服务器可以访问 mysql

查看 mysql 是否运行外界访问

netstat -pna | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      877/mysqld

说明只允许本地访问。

修改 user 表的权限

登陆 mysql。

use mysql

查看用户的权限。

select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

这个只能本地使用。

update user set host = '%' where user = "root";
flush privileges;

修改 mysql 开启的 IP

我的 mysql 配置文件是 /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address = 127.0.0.1
改成
bind-address = 0.0.0.0

然后重启数据库。

service mysql restart

查看现在的 mysql 绑定 IP

netstat -apn|grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      5785/mysqld

查看防火墙以及配置安全规则

ps: 把 3306 端口的出和入规则都配置了。

换个服务器查看连接

telnet 47.242.248.212 3306

出现下面这些就说明外界已经可以访问了。

Trying 47.242.248.212...
Connected to 47.242.248.212.
Escape character is '^]'.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK