远程连接ubuntu系统的mysql服务时发生错误 Error No. 2003 Can't connect to mysql server on '10.15.92.131' (10065)
进入终端命令,输入
nmap localhost -p3306
结果为
Starting Nmap 5.21 ( http://nmap.org ) at 2013-01-09 18:04 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000037s latency).
PORT STATE SERVICE
3306/tcp open mysql
以访问的ip的替代localhost
nmap 10.15.92.131 -p3306
结果为
Starting Nmap 5.21 ( http://nmap.org ) at 2013-01-09 18:04 CST
Nmap scan report for 10.15.92.131
Host is up (0.000045s latency).
PORT STATE SERVICE
3306/tcp closed mysql
两相对比可以看出直接用ip连接的3306/tcp is closed
之后进入mysql命令行后,查看登录用户有无远程连接的权限
use mysql
select host,user from user
如果host为%,则此处正确
+------------------------+------------------+
| host | user |
+------------------------+------------------+
| % | lace |
| % | root |
| 10.15.92.131 | root |
| baowp-work-Lenovo-B460 | |
| localhost | debian-sys-maint |
+------------------------+------------------+
退出mysql命令行,再编辑mysql的配置文件my.cnf
sudo vi /etc/mysql/my.cnf
修改 bind-address = 127.0.0.1 为 bind-address = 0.0.0.0
最后重启mysql
sudo /etc/init.d/mysql restart
再查看 nmap 10.15.92.131 -p3306时看到3306/tcp open mysql,此时可以远程登录
Starting Nmap 5.21 ( http://nmap.org ) at 2013-01-09 18:04 CST
Nmap scan report for 10.15.92.131
Host is up (0.000045s latency).
PORT STATE SERVICE
3306/tcp closed mysql