MySQL:无法通过 SSH 连接到服务器。‘正在读取初始通信包’,系统错误:0

MySQL:无法通过 SSH 连接到服务器。‘正在读取初始通信包’,系统错误:0

我正在运行 Debian 8.2,安装非常新。我尝试使用 Sequel Pro 通过 SSH 连接到我的 MySQL 服务器。我总是收到此错误:

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

当我跑步时

mysql -u root -p

在服务器上,一切都运行正常。但远程则不然。

起初我以为可能是 iptables,所以我(暂时)禁用了所有规则。iptables -L 现在返回:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

然后我检查了 my.cnf,但我能想到的所有参数看起来都是正确的:

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

bind-address            = 127.0.0.1

我的 mysql 日志文件的输出看起来也不错

150609 17:15:07 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150609 17:15:07 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150609 17:15:07 [Note] /usr/sbin/mysqld (mysqld 5.5.43-0+deb8u1) starting as process 18347 ...
150609 17:15:07 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150609 17:15:07 [Note] Plugin 'FEDERATED' is disabled.
150609 17:15:07 InnoDB: The InnoDB memory heap is disabled
150609 17:15:07 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150609 17:15:07 InnoDB: Compressed tables use zlib 1.2.8
150609 17:15:07 InnoDB: Using Linux native AIO
150609 17:15:07 InnoDB: Initializing buffer pool, size = 128.0M
150609 17:15:07 InnoDB: Completed initialization of buffer pool
150609 17:15:07 InnoDB: highest supported file format is Barracuda.
150609 17:15:07 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150609 17:15:08  InnoDB: Waiting for the background threads to start
150609 17:15:09 InnoDB: 5.5.43 started; log sequence number 1654586
150609 17:15:09 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
150609 17:15:09 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
150609 17:15:09 [Note] Server socket created on IP: '127.0.0.1'.
150609 17:15:09 [Note] Event Scheduler: Loaded 0 events
150609 17:15:09 [Note] /usr/sbin/mysqld: ready for connections.

我没有发现我的客户端配置有任何问题:

MySQL Host: 127.0.0.1
User: root
Password: ***
Port: 3306
SSH Host: mydomain.com
SSH User: sshuser
SSH Key: sshkey

/etc/hosts.allow 和 /etc/hosts.deny 中也没有任何内容

请注意,SSH 连接成功,但 MySQL 失败。

我迷路了。有人能帮忙吗?

答案1

好吧,如果有人遇到同样的问题:

注意:设置 SSH 时,必须在 /etc/ssh/sshd_config 中设置以下选项:

AllowTcpForwarding 是

如果不这样做,您的数据包将在服务器上被悄悄丢弃。这将导致上述错误消息。

功劳归于阿赫贝德

相关内容