I wanted to con­nect my MySql server via SSH from remote, but every time I tried to con­nect, i received this error message:

ERROR 2013 (HY000): Lost con­nec­tion to MySQL server dur­ing query” (MySQL Admin) or this error via JDBC:

1
2
3
4
5
6
7
8
9
10
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1934)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:483)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:992)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572)
<>

I found the solu­tion here, edit /etc/mysql/my.cnf, com­ment out the line “skip-networking” and add the “bind-address…” line:

1
2
3
4
5
6
7
<>
# Instead of skip-networking you can now lis­ten only on
# local­host which is more com­pat­i­ble and is not less secure.
# bind-address          = 127.0.0.1
#skip-networking
bind-address            = 127.0.0.1
<>

What did we change? “skip-networking” means, only local (non TCP/IP) con­nec­tions will be allowed, on Unix, con­nec­tions will be made through a Unix socket. By adding the “bind-address” option, we force MySql to lis­ten on 127.0.0.1.

Restart mysqld and MySql will work through SSH (TCP port 3306).