How to remotely connect to a MySQL database located on our shared server

Remote MySQL connection is disabled on our shared servers due to security reasons, but you can easily set up an SSH tunnel between your computer and our server using an SSH client with the MySQL port 3306 forwarding.

After completing it you will have port 5522 on your local machine listening and forwarding to your remote server's localhost on port 3306. Thus, you can connect to the remote server's MySQL database effectively as though it was running on your local box.

NOTE: If you are trying to connect to PostgreSQL databases, use port 5432 instead of 3306.

Below you can find the steps on configuring a third-party SSH client - Putty, and MacOS and Linux built-in one - Terminal.

NOTE: Make sure that the SSH access is enabled for your account. Feel free to follow this guide to check the settings. 

1. Run the application.

2. In the Sessions tab fill out your server hostname or IP-address and port 21098:

3. Switch to the tab Tunnels in the 'SSH' section.

4. You will need to fill in the following information:
  • Source port: 5522
  • Destination:
Click on the Add button:

5. Return to the Session tab, select Default Settings or give your session a new name in the Saved Sessions box and click on Save.

6. Go ahead and run your session by clicking on the Open button:

7. Run your MySQL software on a local machine and use as a server host, port 5522 and your database user login details.

Connect with Terminal (for Linux and MacOS)

1. Run the application and enter the following command:

ssh -f cPanel_username@server_hostname -p21098 -L 5522: -N

Make sure to replace cPanel_username and server_hostname with your actual cPanel account user and server your account is hosted on.

2. Hit Enter and specify your cPanel password (symbols won’t appear in the terminal when you type in the password - it is a terminal way of keeping your password secure).

3. Once done, all connections to localhost over the port 5522 will be forwarded to your hosting account.

You can then use the following command to connect to MySQL:

 /usr/bin/mysql -h -p -u cpuser_dbuser cpuser_dbname -P 3306

For PostgreSQL use this command:

psql -h -p5432 cpuser_dbname cpuser_dbuser

Where cpuser_dbuser is your database username and cpuser_dbname is the database name.

That's it!

                      Need any help? Contact our HelpDesk

114115 times

Need help? We're always here for you.