Remote MySQL connection: how to reach your database from outside

Print
  • 0

In short: a website hosted with TopHost talks to its own database through localhost and needs no extra setup. Remote access matters only when a program on another computer or server must work with the database directly. For security, the server firewall refuses outside MySQL connections by default, so access is granted per IP address: you add the address in cPanel and our support team allows it in the firewall.

Do you really need remote access?

  • To browse, edit, export or import data, phpMyAdmin in cPanel is enough and runs in any browser. See exporting and importing a database with phpMyAdmin.
  • Remote access is useful for desktop tools such as MySQL Workbench, HeidiSQL or DBeaver, for accounting or reporting software that reads the data, and for an application that runs on another server.
  • Every allowed address is a way into your data. Allow only fixed addresses you control, and remove them when the work is finished.

Step 1. Find the public IP address that will connect

You need the public IPv4 address of the computer or server that will open the connection. On a computer, searching "what is my IP" in any search engine shows it. Keep in mind that many home and mobile connections get a new address from time to time. When that happens, access stops working and the new address has to be allowed again. For an office, a static IP from your internet provider saves this trouble.

Step 2. Add the address in cPanel

  1. Log in to cPanel. From the client area, open My Services and choose your hosting plan.
  2. In the Databases section, open Remote Database Access (called Remote MySQL in older cPanel versions).
  3. Under Add Access Host, type the IP address in the Host field, add a short comment such as "office" and click Add Host.

Do not enter a lone % as the host: it is a wildcard that would accept any address on the internet.

Step 3. Ask us to open the firewall for that address

Open a ticket and include:

  • the public IP address from step 1;
  • the domain or the cPanel username of the hosting account;
  • the full database name and database user, with the prefix (for example cpuser_shop);
  • what will connect (a program on your computer, a server of yours, a partner's application).

There is no need to put the database password in the ticket. Our support team answers once the address is allowed.

Step 4. Fill in the connection settings in your program

SettingValue
HostYour domain name, if it points to the TopHost hosting, or the server IP that cPanel shows under General Information (Shared IP Address)
Port3306
UserThe full database user name, prefix included
PasswordThe password of that database user
DatabaseThe full database name, prefix included

If your domain goes through the Cloudflare proxy (orange cloud), use the server IP as host. The proxy carries web traffic only, not MySQL.

When the connection fails

  • "Access denied for user": the user name or password is wrong, the user was never added to the database (see creating a database and user), or the IP is missing from Remote Database Access.
  • Timeout or "Can't connect to MySQL server": the firewall has not been opened yet, your IP has changed, or your own network blocks outgoing traffic on port 3306 (common on office and public Wi-Fi networks).
  • It worked and then stopped: several failed logins in a row can get an IP blocked by the server firewall. The reasons are listed in why the server firewall blocks an IP address.

Still no luck? Write to us in the same ticket with the exact error message and the time of your last attempt.

A safer option: an SSH tunnel

If SSH is enabled for your account (see connecting to the server via SSH), MySQL Workbench, HeidiSQL, DBeaver and similar tools can connect through an SSH tunnel. The database is then reached as if from the server itself, with localhost as the MySQL host, and port 3306 does not have to be opened to the internet.

The other direction: your site connects to an outside database

If a script on your TopHost hosting has to reach a database on another server, the firewall may filter that connection too. Open a ticket with the address and port of the remote server and we will check it.

Related articles

Was this answer helpful?