1. Knowledge Base
  2. >
  3. Results
  4. >
  5. How to Connect to the MySQL Database Remotely

How to Connect to the MySQL Database Remotely

Allowing remote MySQL connections is often done to enable a program on your personal computer to access a database on the server.

If you are connecting from your home computer, you need a MySQL client like Navicat, phpMyAdmin, Workbench, or Dreamweaver.

For some suggested programs and more details, please see:

Click the links below for the instructions.


How to Enable Your Computer as an Access Host

By default, all IP addresses are blocked and must be added to a list in order to access the server. So, before connecting to MySQL from another computer, the connecting computer must be enabled as an Access Host.

Dynamic IP Addresses

Having a dynamic IP address means that the connecting IP address can change periodically, depending on the Internet Service Provider (ISP). You must update the connecting IP in Remote MySQL every time it changes.

Many of our servers block port 3306 inbound. If you are getting a Connection Refused error when trying to connect, please contact us via phone or Live Chat requesting that we open port 3306 for your IP to connect to MySQL remotely.

Here is a video showing how to add your IP address as an Access Host in cPanel. The Remote MySQL shown may look slightly different depending on which cPanel version your server is running; however, the functionality described in the video is the same.


via cPanel

To add your computer as an Access Host as shown in the video above:

  1. Log into cPanel.
  2. Under the Databases section, click Remote MySQL®.

    cPanel - Remote MySQL

  3. Enter the connecting IP address, then click Add.
    To know what your current local IP address is, please visit hostgator.com/ip.

    Remote MySQL - Add IP Address

To remove a host from accessing databases on your server:

  1. Click the Remote MySQL® icon under the cPanel’s Databases section. 
  2. Locate the IP address you wish to remove.
  3. Click the Delete icon on the right-hand side of the selected IP address.

    Remote MySQL - Remove IP Address

via Plesk

If you have Windows hosting, you will need to whitelist your IP. Please follow the instructions in the following articles:


What Are the Configuration Settings

Use the following configuration settings to connect to your database.

HostnameUse the server IP address or server name. Please refer to this article to know where to find your server address: What is My Server Address?
Database NameUse the first 8 characters of your cpanelUsername_databaseName.
 

Example:
cPanel username: snappygator
Database name: exampledatabase

Output:
snappyga_exampledatabase
 
Database UsernameUse the first 8 characters of your cpanelUsername__databaseUsername.
 

Example:
cPanel username: snappygator
Database username: exampleuser

Output:
snappyga_exampleuser

Database PasswordThe password you entered for that database user.
MySQL Connection Port3306
TCP or UDPEither of the two is fine.

To learn more about adding a connection string to your Perl or PHP code using these configuration settings, please see the following article:


How to Access Your Databases

After whitelisting your local IP, you should be able to make the proper remote MySQL connection. Be sure that the username and password you will use match the ones created in the MySQL Database section of cPanel. The most common problem in connecting is due to the use of incorrect username and password.

For more examples of common MySQL errors, please see the related article:


Related Topics:

What is a MySQL database server?

MySQL is an open-source management system used to create and manage databases. Basically, a MySQL server is like a database engine where you can store data and allows you to access and maintain those data in a systematic and efficient way.

How to Add a User to Access to the MySQL Database?

Aside from the configuration settings needed to connect to a MySQL database, a user is also required to have certain privileges. Please refer to these articles to know more about how to grant privileges to users and to configure connection settings.

How to Allow Remote Access to a MySQL Server?

The MySQL server communicates only from the “localhost” by default, which means it can only be accessed by applications running on the same host. Remote access is necessary if you wish to access the database from an application running on a different machine or host.

To connect remotely, you will need to get your connecting computer-enabled as an Access Host by whitelisting your local IP address. You will also need to identify your configuration settings, as shown above.

How Do You Find the MySQL Hostname?

The MySQL Hostname is the location of your MySQL server and database. This information is needed whenever you need to connect to your MySQL server. Localhost is used by default as the hostname provided that you are accessing your database on the same server where your application is, like WordPress. For a WordPress site, your hostname is found in your directory root’s wp-config.php file.

Example of WordPress Hostname

To access the database remotely, you may want to use your server IP address or server name instead of “localhost” to initiate a connection.

How Do You Restore a MySQL Database?

The cPanel has a feature that allows you to restore a MySQL Database backup. The instructions on how to restore a MySQL backup are outlined in this article, Download and Restore MySQL Database Backup.

Alternatively, you also have the option to do a restoration through your cPanel’s phpMyAdmin by importing your backed up MySQL database file. Please refer to the article below for instructions. A video guide is also included in the article to assist you with the whole process.


Related Articles:

Troubleshooting MySQL Database Connection Issues
MySQL Connection Strings