# Allow remote MySQL connections
Source: https://docs.webgee.com/en/databases/mysql-remote-connections



Allow a machine outside your hosting account — a local development environment,
a reporting tool, a separate application server — to connect to your MySQL
databases. Applies to shared and reseller hosting.

Remote MySQL is disabled by default because an openly reachable database is one
of the most commonly attacked services on the internet. You are opening it to
specific addresses only.

<Callout type="warn">
  Never add `%` as an access host. That grants every address on the internet
  permission to attempt a login against your database.
</Callout>

## Before you begin [#before-you-begin]

You need the public IP address of the machine that will connect. On that
machine, visit any "what is my IP" service, or run:

```bash
curl -s https://ifconfig.me
```

If your connection uses a dynamic IP, it will change — you will need to update
this list when it does.

## Grant access [#grant-access]

1. In cPanel, open **Remote MySQL** under **Databases**.
2. In **Add Access Host**, enter the IP address.
3. Select **Add Host**.

To revoke access later, select **Delete** beside the entry.

## Connect [#connect]

Use your domain as the host, and your existing cPanel database credentials:

```bash
mysql -h example.com -u cpaneluser_dbuser -p cpaneluser_dbname
```

The username and database name both carry your cPanel username as a prefix. You
can see the exact values under **cPanel → MySQL Databases**.

## Check it worked [#check-it-worked]

From the machine you granted access to:

```bash
mysql -h example.com -u cpaneluser_dbuser -p -e "SELECT 1;"
```

A `1` back means the connection, the credentials and the grant are all correct.

## If the connection is still refused [#if-the-connection-is-still-refused]

Work through these in order — they cover nearly every case:

* **Your IP address changed.** Most home and office connections have dynamic
  addresses. Re-check your current IP and add it.
* **The database user has no privileges on that database.** Adding an access
  host does not grant a user access to a database. Check
  **cPanel → MySQL Databases → Add User To Database**.
* **Port 3306 is blocked at your end.** Many corporate networks and some ISPs
  block outbound MySQL. Test with `nc -vz example.com 3306`.
* **WebGee is blocking it upstream.** We block inbound MySQL at the network edge
  when we see attacks against `mysqld`. If everything above checks out, open a
  ticket and ask for your IP to be added to the allow list.

## Related [#related]

* [Create and manage MySQL databases](/en/databases/how-to-create-and-manage-mysql-databases-in-cpanel)
* [Import a large database](/en/databases/how-to-import-a-large-database-into-mysql)
