Connecting MySQL server on Amazon EC2 instance using ssh tunnel


SSH tunnel basically does the port forwarding via secure ssh service.

Let’s start with launching a latest hardened AMP stack AMI (ami-e0b05389) instance.
Once the instnace is up and running, open the terminal client and connect to the instance using ssh.

Edit the /etc/ssh/sshd_config file and set AllowTcpForwarding to yes

AllowTcpForwarding yes

Restart ssh service

svcadm restart svc:/network/ssh:default

Comment out skip-networking from /etc/mysql/my.cnf and save the file

#skip-networking

Restart MySQL service

svcadm restart svc:/application/database/mysql:version_51

exit the ssh connection and recreate ssh connection using following command.

ssh -i <keypair> -L 3307:localhost:3306 root@ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com

Keep the terminal opened, and start MySQL Query Browser / MySQL administrator from your local machine. and  connect to the MySQL server on remote EC2 instance via the port 3307, as shown in the following sanpshots.

 

When done close the ssh connection and it should close the ssh tunnel.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s