Skip to main content
To allow remote connections to MySQL or MariaDB, set bind-address = 0.0.0.0 in the server config (/etc/mysql/mariadb.conf.d/50-server.cnf for MariaDB or /etc/mysql/mysql.conf.d/mysqld.cnf for MySQL on Ubuntu), restart the service, create a user for the client’s IP such as 'app'@'198.51.100.25', and allow port 3306 in your firewall from that IP only.

Before you start

  • Know the public IP address of the machine that will connect (your app server or your home connection). In these examples the client is 198.51.100.25 and the database server is 203.0.113.10.
  • Have a firewall running. See UFW or firewalld.
  • Back up your databases before changing the server.
If only you need access (for example from HeidiSQL or MySQL Workbench), you do not need remote access at all. Use an SSH tunnel instead and keep the database closed to the internet. See connect with HeidiSQL.

Why can’t I connect to MySQL remotely?

On Ubuntu and Debian, MySQL and MariaDB only listen on 127.0.0.1 after installation, so only programs on the server itself can connect. Remote access needs three things to line up:
  1. The server listens on a public address (bind-address).
  2. A database account exists for the client’s IP address.
  3. The firewall lets that IP reach port 3306.

How to allow remote MySQL connections

1

Change bind-address

Open the config file for your server:
Under [mysqld], change the line to:
0.0.0.0 listens on every IPv4 address. To listen on one address only, use the server’s IP, for example bind-address = 203.0.113.10. If the file contains skip-networking, remove that line or comment it out with #.
2

Restart the database server

3

Create a user for the client's IP

Open the shell with sudo mariadb (or sudo mysql) and run:
This account only works from 198.51.100.25. A user that already exists for localhost is a separate account and keeps working.
4

Open port 3306 to that IP only

Never run ufw allow 3306 or firewall-cmd --add-service=mysql without a source address on a public server. That opens the database to every IP on the internet, and automated scanners will start guessing passwords. Also avoid 'user'@'%' accounts unless the firewall already limits who can connect.

How to check it worked

On the server, check what MySQL listens on:
If it still shows 127.0.0.1:3306, the bind-address change is in the wrong file or the service was not restarted. MariaDB can print the setting it actually uses:
From the client machine, connect with the MySQL client:
A mysql> or MariaDB [shop]> prompt means it works. To test only the port, see check if a port is open from outside.

Troubleshooting remote MySQL connections

Frequently asked questions

Is it safe to set bind-address to 0.0.0.0?

Only together with a firewall rule that allows specific IPs. bind-address decides which addresses MySQL listens on; the firewall decides who can reach them.

My home IP changes. What should I do?

Use an SSH tunnel instead of opening the port. A tool such as HeidiSQL connects over SSH and reaches MySQL on 127.0.0.1, so nothing extra is exposed.

Does remote MySQL traffic use encryption?

Not unless you set up TLS. Without it, queries and data cross the internet in plain text. An SSH tunnel or a private VPN such as WireGuard encrypts the connection.

How do I undo remote access?

Set bind-address = 127.0.0.1 again, restart the service, delete the firewall rule and run DROP USER 'shopuser'@'198.51.100.25';.

VPS and dedicated server guides

Every guide in this section.

Create a database and user

How the user and host part work.

Connect with HeidiSQL

Use an SSH tunnel instead.

Set up UFW

Allow ports from chosen IPs.

Check open ports

See what your server listens on.

Checked against the official MariaDB remote connection guide, Ubuntu Server documentation and Red Hat database server guide on 4 November 2026; config files, SQL and the UFW rule (dry run) tested on Ubuntu 24.04 LTS with MariaDB 10.11. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026