我正在运行以下 mysql 命令:
mysql -h 10.8.0.16 -u username -p
输入密码后,出现以下错误:
错误 2003 (HY000):无法连接到‘XXX.XXX.XXX.XXX’上的 MySQL 服务器 (111)
以下是/etc/mysql/mysql.cnf
!bind-address = 0.0.0.0
!server-id = 1
#!relay-log = /var/log/mysql/mysql-relay-bin.log
!log_bin = /var/log/mysql/mysql-bin.log
#!binlog_do_db = newdatabase
!ibinlog-ignore-db = "database"
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
这是我的结果netstat
$ netstat -an | grep tcp | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:57630 127.0.0.1:3306 ESTABLISHED
tcp 0 0 127.0.0.1:3306 127.0.0.1:57630 ESTABLISHED
tcp 1 0 127.0.0.1:57628 127.0.0.1:3306 CLOSE_WAIT
tcp 1 0 127.0.0.1:57570 127.0.0.1:3306 CLOSE_WAIT
tcp 1 0 127.0.0.1:57600 127.0.0.1:3306 CLOSE_WAIT
tcp 1 0 127.0.0.1:57594 127.0.0.1:3306 CLOSE_WAIT
tcp 1 0 127.0.0.1:57608 127.0.0.1:3306 CLOSE_WAIT
答案1
你的 MySQL 配置为仅绑定到127.0.0.1
。正确配置 bind-address:
/etc/mysql/my.cnf:
bind-address = 0.0.0.0
之后不要忘记重新启动 mysqld。