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

Øle*_*oem 3 mysql debian ssh

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

Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Run Code Online (Sandbox Code Playgroud)

当我跑

mysql -u root -p
Run Code Online (Sandbox Code Playgroud)

在服务器上,一切正常。但不是来自远程。

一开始我还以为是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
Run Code Online (Sandbox Code Playgroud)

然后我检查了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
Run Code Online (Sandbox Code Playgroud)

我的 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.
Run Code Online (Sandbox Code Playgroud)

而且我找不到客户端配置的任何问题:

MySQL Host: 127.0.0.1
User: root
Password: ***
Port: 3306
SSH Host: mydomain.com
SSH User: sshuser
SSH Key: sshkey
Run Code Online (Sandbox Code Playgroud)

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

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

我搞不清楚了。有人可以帮忙吗?

Øle*_*oem 6

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

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

AllowTcpForwarding 是

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

信用去achbed