Connect to a MySQL database using SSH Tunnelling


Connect to a MySQL database using SSH Tunnelling

You will need SSH to be enabled for this to work. Click here for a guide on doing that.

Windows Guide
There are many programs available for creating an SSH tunnel. We will be using Bitvise Tunnelier, which you can download and install here:

Once you have downloaded and installed Tunnelier, you will need to configure it.

How to configure Tunnelier:

  1. Under the Login tab, enter in the following information --
    1. Server Host: Your Domain Name
    2. Username: The cPanel username for your account
    3. Password: The cPanel password for that account
  2. Change the Initial Method to "password"
  3. Tick the box for Store encrypted password in profile

  4. Under the Options tab untick Open Terminal and Open SFTP
  5. Under the C2S Fwding tab you will need to add some details about the connection forwarding.
    Click the Add button and enter these details:
    enabled 3306 DomainName 3306 MySQL


    However, if for some reason that you are running a MySQL server on your PC (you probably are not), then change "List. Port" to 3308 for example
  6. You are now ready to connect to your Web Hosting Account using the SSH tunnel.
    Click the Login button on the bottom left-hand side of the program.
  7. Click the Accept and Save button when the Host Key Verification window when it pops up

You will now be able to see the results of your connection attempt in the Log window. After the connection has been established, load whichever program that you are using to access your databases and configure it to connect to localhost (or on port 3306 (or port 3308 if you set it to that instead).

Click the Logout button to close the connection.

Mac Guide
Step 1 - Open the Terminal application from Go > > Applications > Utilities

Click on Terminal


Step 2 - In the Terminal, run the following command: ssh cpanelusername@hostip -Llocalport:

Cpanelusername your cpanel account username
hostip the IP address off your server
localport a random port number (1211 is safe as it’s not a standard port)

Your SSH Tunnel should now be working

Did you find this article useful?  

Related Articles

© Crucial