Setting up a Remote MySQL connection in cPanel

In this tutorial:

If you need to connect to your database using third party software that does not run on the server, such as a MySQL client on your desktop a remote MySQL connection can be made. First you will have to allow the connection from within cPanel for the IP address you are connecting from.

What program do I use to connect Remotely?

There are a few programs you can use to connect remotely to your database. HTML editors like DreamWeaver can connect to your databases remotely as well. There are Free Open Source programs you can use like MySQL Workbench or or Heidi SQL. Below are some links to programs you can use to connect to your databases remotely.

Adding an IP address to allow a remote MySQL connection

First, you will need to make sure you have the IP address that will be accessing the database. These rules protect the database by only accepting external connections that you have set up. If you are connecting to a database from your current connection, you can obtain your current IP address by visiting this link: current IP address. Once you have the IP address that you wish to connect remotely, log into cPanel and click on "Remote MySQL" under the Databases Heading.

Next, you'll need to add the IP address into the field on the page and select "Add Host".

Now, since you have added the IP address to remote MySQL connections you will be able to connect to the databases. You can add as many IP addresses as you need.

Using a Wildcard to allow all IP's

You may find you need to use a wildcard if your IP address changes regularly. You can add a wildcard by using the % symbol. This will add all IP addresses in that range.

If you want to list all IP addresses in the range 174.77.92.1 to 174.77.92.255 you'd add the IP address 174.77.92.%.

Troubleshooting Remote connection issues

If you are using your preferred remote connection tool and suddenly it will not connect. This error is known as a 1045 and usually reads similar to '1045 - access denied for user'. If you are getting this error, there are a couple of things listed below that you may want to check.

Check your cPanel password

Many people connect remotely using their cPanel username and password as opposed to creating a single administrative user to add to the databases. This is not the preferred method, however if you do use the cPanel username and you are now getting a connection error, chances are you recently changed the cPanel password and have not changed it in the Remote connection software settings. Change the password there and you should be able to connect once again.

Check to see if connecting IP has changed

Not all of us are blessed with static IP addresses. From time to time your ISP (Internet Service Provider) may change your public IP address. If that is the case, you may find yourself unable to connect remotely via your preferred software. First, check your IP address by going to Google.com and searching for the term IP. You can also find your current IP address by clicking here.

Once you know your current IP address, go back and make sure that it is in the list of allowed IP addresses for your Remote MySQL settings. If you find it was not in the list and add the new one, you should then be able to connect remotely.

Apologies, but this is a general article about making a remote connection to a database. Access to the database is generally based on the URL used to get to the server, and the user name and password assigned to the database you're trying to access. You will need to provide your IP address in order to allow the access through the firewall. This access is ONLY for database access (which occurs by default through a specific port). All of this is determined the Remote MySQL setup.

If you have any further questions, please contact technical support or leave a comment at the bottom of the page.

If you want to allow all IP addresses to connect to a remote MySQL server, you would use wildwards such as %.%.%.% which would allow any IP address to connect. Doing so, however, is a very large security risk and I highly recommend against it.

I'm trying to synchronize data tables local install (mamp) phpmysqladmin and it failes. I'm unable to troblehoot with telnet connection.

Upon telneting to my site, it ask only for password and not a username. I already assigned username and password for specific database. Which password is it waiting for? cpanel, my domain login to inmotion, or something else?

After several failed attempts, i'm not allowed connet back to my ip address and get a packet out of order.

The error message attempting to connect:

5.5.36-cll?r"L=*W\?*?<P]cZwg"n(mysql_native_password (mypasswordhere)!#08S01Got packets out of orderConnection closed by foreign host.

?Host '107-223-112-160.lightspeed.sndgca.sbcglobal.net' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'Connection closed by foreign host.

Do i have the 'mysqladmin flush-hosts ability? It doesn't work in sql screen and looks like a command prompt from the unix shell. I don't have access directly to that unix shell that i'm aware of.

First, you will not be able to telnet into your account. You will have to use a remote MySQL connection instead. When logging in remotely, you will be using the username and password to the MySQL user that is accessing the database that you want to connect to. This is something that you would have created within cPanel. As for the flush-hosts issue, this is caused by too many bad connections to the server and would need to be resolved by contacting technical support.

This guide just covers how to allow a remote MySQL connection into the server. If you're looking for how to connect to MySQL from PHP, we do have a guide on connecting to MySQL with PHP that does go over mysql_connect with this bit of code in the second step of the guide:

What code are you trying to currently use, and is it resulting in any errors? Also are you allowing the remote IP address of the server that you're running your PHP script from? Because that's the one that will need to be added, and not your local IP if the PHP server is running from another server.

There is an explanation as well as examples of mysql_connect from the PHP.net site.

If your script works locally but not remotely, I'd try this basic example:

After ensuring that the localhost variable is set to the server that is hosting your MySQL database, and also that the mysql_user, and mysql_password settings are correct what error is it giving back after the Could not connect: text?

I'd assume either the server address you're using, or the username and password are incorrect based off that error. Either that or possibly you have a local firewall running that is preventing the outbound connection on port 3306.

Yes you do need a different username / password typically for a remote connection. This would be the database username and password that you setup on the remote server. For instance you need to create and attach a database user to a database in order to remotely connect to it.

I'm trying to connect to my remote MySQL database using a JAVA program (that I used to process data from a CSV file). It all works fine when I connect to my local database, but when I change the settings to access the remote database, I can't connect. I discovered this morning that I don't have SSH access to the remote database; does this mean that I will not be able to connect remotely using my JAVA app? Will I have to use something like WorkBench or Heidi? (I have got PHPMyAdmin access through cPanel, but it would be much quicker to load the database directly from the JAVA app.)

As long as your IP is added to the Remote MySQL Connection tool and the settings are correct, there should be no issue with you connecting to the database remotely. You may opt to use Workbench, NaviCat, or Heidi as well, but they require the same setup as your Java app would. It may be good to test with one of those other applications as well as part of the troubleshooting process.

Within the snippet you provided, have you tried using the IP address instead of the domain name? Also, are you adding /dbname at the end before you provide the username and password? It should appear something like this:
jdbc:mysql://123.123.123.123/db_name, db_user, password

What is the error that you're getting about problems connecting to the database? It's hard to troubleshoot without seeing your full code or the specific error. I would make sure to reference the connecting to MySQL using JDBC guide from MySQL.

Also you want to make sure that your host is a valid entry that your Java application can connect remotely to. So I'm not sure if you were just using jdbc:mysql://%.%.%.%/a21_senkwaepos as an example. But that needs to be a valid IP address or hostname:

Hello sir, i've make a remote database in cpanel on my hosting, but i cant acces thaint database both in heidi sql, navicat or from my program (written in C#). my program gimme error "Unable to connect to any of specified my sql host". Btw, i used mysql connector for .NET