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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Divyen Patel

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today