..a dose of zero-day know-hows ..

1/15/2007

Issues when Tunneling MySQL

If the following error message ring a bell to you:

"ERROR 2013 (HY000): Lost connection to MySQL server during query"

And you have set up SSH tunnelling to secure your MySQL connection, check if you have complied with the following checklist:

  1. Is "AllowTcpForwarding yes" set on the /etc/ssh/sshd_config of the MySQL Server? If not, set this directive to yes and restart SSH. It might be necessary to restart the server machine as shutting down SSHD alone will block you out from a remote server as you will have no access except by physically interfacing with it.
  2. Is SSH on the originating server running on the background specifically the SSH tunneling command you executed? Check this using the command "top" or "ps -ef | grep "ssh"". If you dont see the process you ran to tunnel MySQL, then run it.
  3. If you are using the root account to do the tunnel from the originating server, make sure that the "PermitRootLogin" is set to yes on the "/etc/ssh/sshd_config" of the MySQL Server. If this isnt set, set it and restart the SSHD daemon by restarting the server.
This is a sample SSH tunnel command to forward local(originating) MySQL connections to a remote MySQL Server:

"ssh -N -f -g -L 3306:localhost:3306 root@mysql_server.com"

The above command tells SSH to forward all local connections from port 3306 to mysql_server.com on port 3306 and use the root credential to connect. The above command will also run on the background so you may have to "kill" it if you no longer need it to be running.

For more info, visit the following link:
SSH Tunneling on Google.com