您的位置:首页 > 数据库 > MySQL

腾讯云服务器Mysql开启3306端口远程访问

2017-11-04 23:41 946 查看

0. 概要

现在需要使用自己计算机上的
Mysql Wordbench
客户端来连接云服务器上的
Mysql
数据库。

1. 记录过程

查看Centos版本

[root@VM_0_7_centos ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)


查看当前 Ubuntu Server版本

ubuntu@VM-15-131-ubuntu:~$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:    16.04
Codename:   xenial


修改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端口是否状态

ubuntu@VM-15-131-ubuntu:~$ netstat -an | grep 3306
tcp6        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


ubuntu@VM-15-131-ubuntu:~$ /etc/init.d/mysql restart
[....] Restarting mysql (via systemctl): mysql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Authenticating as: ubuntu,,, (ubuntu)
Password:
==== AUTHENTICATION COMPLETE ===
. ok


再看3306端口状态

netstat -an | grep 3306


ubuntu@VM-15-131-ubuntu:~$ netstat -an | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN


3. 使用
Mysql Workbench
测试连接

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: