Showing posts with label Lost connection to MySQL server at 'reading initial communication packet. Show all posts
Showing posts with label Lost connection to MySQL server at 'reading initial communication packet. Show all posts

Thursday, October 17, 2019

Connect to RDS through EC2 on local mysql workbench

If you are connecting AWS RDS through EC2 instance from mysql workbench on your local using method 'Standard TCP/IP over SSH' as you do not want to open mysql port 3306 globally. You have opened 3306 port of RDS for EC2 instance only as it should be connected from EC2 only.

 You first connect to EC2 using ssh (key file) and then EC2 makes connection to RDS. This is quite common approach to access RDS database on local.

But in this approach you may get error
Failed to Connect to MySQL at 3306 through SSH tunnel at with user
"Lost connection to MySQL server at 'reading initial communication packet, system error: 0"



The reason behind this error, ssh config is not allowing tcp forwarding. You need to make it allowed.
Open file /etc/ssh/sshd_config and check attribute 'AllowTcpForwarding'. The value is set to no that;s why you are getting the error.
The value should be Yes for the parameter.
AllowTcpForwarding Yes
Now after changing value, restart ssh and try to connect again from mysql workbench. The connection should be made successfully.