MySQL Forums
Forum List  »  PHP

Re: Lost connection to MySQL server at 'reading initial communication packet', system error: 111
Posted by: Robert Moore
Date: January 06, 2009 11:06AM

I grappled with this issue for several hours yesterday and I eventually got it working by matching the "remote address" in the SSH command to the bind-address value in the my.cnf file on the remote server. For most people, the bind-address value is 127.0.0.1, but I have my MySQL server bound to a local network address (192.168.0.x). The correct command for me, therefore, was:

ssh -v -f -N -L 3307:192.168.0.1:3306 user@host.server.com

It seems that the "remote address" in the SSH command is the value used by MySQL to associate the tunneled user with an IP address. Depending on your configuration, MySQL likely either refuses connections from remote IPs or only allows the user you are logging in as to log in from locahost. Since we can't self-identify as "localhost" (we have to force TCP activity) we need to use an IP address, and that IP address needs to be whatever MySQL identifies as its own. This is the value of bind-address. In many cases, this is going to be 127.0.0.1 (that's why you see this proposed solution everywhere), but that's not always the case. Check your bind-address value!

In short, if you're getting an error in the the "Channel x open failed: connect failed: Connection refused" universe, make sure that the "remote address" in your ssh command matches the bind-address value on your remote machine.

Here are my full notes from yesterday: http://themetricsystem.rjmetrics.com/2009/01/06/php-mysql-and-ssh-tunneling-port-forwarding/

I hope this is helpful to someone.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.