How to connect to your MySQL database remotely
Connect a database client on your own computer (for example TablePlus, DBeaver or HeidiSQL) to a MySQL database on your host. The recommended, secure way is an SSH tunnel.
Why the database port is not open by default
For security, MySQL listens on localhost only (mysql_bindaddress: "127.0.0.1"), so the database
port is not reachable from the internet. Rather than exposing it, you forward it over your existing
SSH access - the connection is encrypted and uses your SSH key.
Connect over an SSH tunnel (recommended)
- Open a tunnel from a local port (here
3307) to the database on the host:Leave this session open while you work.ssh -L 3307:127.0.0.1:3306 prod@web1.example.com -
Point your client at the local end of the tunnel:
Many clients (TablePlus, DBeaver, HeidiSQL) can also create the SSH tunnel for you - choose "SSH" or
"connect over SSH" and give your SSH host and key; then set the database host to 127.0.0.1.
Opening the port instead (advanced)
If a tool genuinely cannot tunnel, you can widen the bind address and allow specific source IPs - but this exposes the database, so prefer the tunnel.
-
Set
mysql_bindaddressto a non-local address in the host configuration (see Configure MySQL). -
Allow only the exact source IP addresses on the host's Security tab (Security). Adding an IP to the allow-list there also opens the otherwise blocked database port to it.
-
Connect with a least-privilege user, never the application's main user.
Warning
Never open the database to 0.0.0.0 or a broad range. Expose it only to specific, trusted IP
addresses, and use a dedicated read-only or limited user.
Troubleshooting
-
Connection refused - the tunnel is not open, or the client is pointing at the host instead of
127.0.0.1. -
Access denied - wrong user/password, or the user is not allowed from your host (see Create and manage database users).
-
Times out when opening the port directly - the source IP is not on the allow-list, or
mysql_bindaddressis still local. See Database problems.
Related
- Configure MySQL
- Create and manage database users
- Import and export a database
- SSH access
- Host Security tab