Monday 6 February 2012

Connect to MySql via SSH tunnel

You have your Mysql database up and running in production. You are happy connecting to server by ssh and doing everything using console. Felt like you miss something here. Yes you miss a good mysql client here. As security is of prime importance you cant enable your mysql to accept connections from outside localhost.

So how to do this in a secure manner?  SSH tunneling is the answer. After following these instructions, you'll be able to connect to localhost on your workstation using your favorite MySQL management tool. The connection will be securely forwarded to your Cloud / server space over the Internet.



Step 1 Download Putty


Download putty, if you don't have it now. You can get it here.

Step 2 Configure SSH connection to your server


Open putty and configure your connection to the remote server.



 Step 2 Configure Tnnel in Putty


Visit the "Connection -> SSH -> Tunnels" screen in PuTTY. Enter "3300" for the "Source port" field and "localhost:3306" for the "Destination" field, as shown below. Remember , source field your local  machines free port, and destination is your server port. Destination is given as localhost because for putty, once connected the connected server is the localhost.






Once you've connected to the remote server with this tunnel configuration, you'll be able to direct your local MySQL client to localhost:3300. Your connection to the remote MySQL server will be encrypted through SSH, allowing you to access your databases without running MySQL on a public IP.

Do let me know your questions?














1 comment:

Simon John said...

Good information for all web developers who is using mysql