MySQL 开启 3306 端口远程访问
查看当前 Ubuntu Server 版本
sudo lsb_release -a
修改 user
表里面的 host
项
登入mysql后,更改
mysql
数据库里的user
表里的host
项,从localhost
改称%
mysql -uroot -proot
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
查看3306端口状态
netstat -an | grep 3306
root@ubuntu:~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
可以发现: 3306端口绑定的IP地址是本地的127.0.0.1 , 需要解绑
修改Mysql配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address 并在前面加上 # 注释该行
#bind-address = 127.0.0.1
重启Mysql让配置文件生效
运行
/etc/init.d/mysql restart
再看3306端口状态
netstat -an | grep 3306
root@ubuntu:~# netstat -an | grep 3306
tcp6 0 0 :::3306 :::* LISTEN
再次尝试远程链接
本作品采用《CC 协议》,转载必须注明作者和本文链接