Skip to content
Follow
Ubuntu Linux

How to Allow Remote Connections to MySQL Database Server

Richard
Written by
Richard
Mar 17, 2026 Updated Oct 4, 2026 7 min read
How to Allow Remote Connections to MySQL Database Server
How to Allow Remote Connections to MySQL Database Server

By default, MySQL accepts connections only from the machine it runs on. It listens on the loopback address 127.0.0.1, so other computers on your network or the internet cannot reach it. That is a sensible default for security, but it gets in the way when an application server, a colleague’s workstation or a reporting tool needs to reach the database.

Advertisement

Allowing remote access takes four changes on the server:

  1. Change the bind-address setting in the configuration file to 0.0.0.0.
  2. Restart MySQL so the change takes effect.
  3. Create a user account that is allowed to connect from the remote machine.
  4. Open port 3306 in the firewall.

Once other machines can connect, the strength of your passwords is what protects your data. Use long, unique passwords for every remote account.

⚡ Quick Answer

Edit the MySQL configuration file and change bind-address from 127.0.0.1 to 0.0.0.0, then restart MySQL with sudo systemctl restart mysql. Create a remote user account with CREATE USER ‘user_name’@’ip_address’ IDENTIFIED BY ‘password’, grant privileges, and open port 3306 in your firewall.

Advertisement

Step 1Configure MySQL to Listen for Remote Connections

The bind-address setting tells MySQL which network interface to listen on. While it points at localhost, the server ignores traffic from other machines. Changing it to 0.0.0.0 makes MySQL listen on all IPv4 interfaces of the server, so you can then control who gets in with user accounts and firewall rules.

This section covers MySQL on Linux. The location of the configuration file depends on the distribution:

  • Ubuntu/Debian: /etc/mysql/mysql.conf.d/mysqld.cnf
  • Fedora/RHEL: /etc/my.cnf
⚠️WarningYou need administrator (root or sudo) rights to edit these files and to restart the service.

Make a copy of the file before you change it. If something goes wrong, you can put the original back.

Advertisement

For Ubuntu or Debian users:

  1. Open the settings file in a text editor, using the command below. You should see the contents of the configuration file.
🐧Bash / Shell
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  1. Find the bind-address parameter. By default it points at the local machine.
💻Code
bind-address           = 127.0.0.1
  1. Change the value so MySQL accepts connections on all interfaces, as shown below.
💻Code
bind-address           = 0.0.0.0
  1. Look for a skip-networking line further down. If it exists, put a # character at the start of the line. This comments the line out and disables that restriction.
💻Code
# skip-networking
  1. Save the file and exit the editor.

The change does nothing until MySQL is restarted. The restart commands are further down this section.

For Fedora or RHEL users:

  1. Open the settings file with a text editor, as shown below.
🐧Bash / Shell
sudo nano /etc/my.cnf
  1. Find the bind-address line beneath the [mysqld] section. If it is not there, add it under that section and set it to 0.0.0.0. The line must sit inside that section, or MySQL will ignore it.

Step 2Restart MySQL

  1. Save the file and exit the editor.

⚠️ Admin privileges required

Advertisement

Restart the MySQL service so it reads the new setting. Use the command for your distribution.

For Ubuntu or Debian:

🐧Bash / Shell
sudo systemctl restart mysql

For Fedora or RHEL:

🐧Bash / Shell
sudo systemctl restart mysqld

If the service fails to start, you most likely have a typo in the configuration file. Re-open the file and check the lines you edited. To undo the change, restore your backup copy or set the bind address back to its old value, then restart the service again.

Advertisement

Step 3Create a User for Remote Access

MySQL accounts are tied to a host as well as a name. An account created for localhost cannot be used from another computer, even with the right password. You need a separate account that names the remote computer's IP address, or one that allows any address. You create it from the MySQL shell as the root database user.

  1. Log into MySQL as the root user, using the command below. You should land at the MySQL prompt.
🐧Bash / Shell
sudo mysql

If your root account uses a password instead, authenticate with it using this form:

💻Code
mysql -uroot -p
  1. Create the new user account. Replace the placeholder values with your own details.
💻Code
CREATE USER 'user_name'@'ip_address' IDENTIFIED BY 'user_password';
  1. Grant privileges on the database to the new account.
💻Code
GRANT ALL ON database_name.* TO 'user_name'@'ip_address';

Each placeholder in these commands has a specific purpose:

  • user_name = the name of the new user
  • ip_address = the IP address of the remote computer (use % to allow any IP)
  • user_password = the password for this user
  • database_name = the database the user can access
⚠️WarningUse a specific IP address where you can.

Allowing any IP means anyone who can reach the server can try to log in as that user. Give the account access only to the database it needs, and nothing more.

Advertisement

Example:

To create an account named "john" that connects from IP 10.8.0.5 with the password "secure123" and works with the "sales_db" database, use this syntax. Choose a stronger password on a real server.

💻Code
CREATE USER 'john'@'192.168.0.1' IDENTIFIED BY 'secure123';
GRANT ALL ON sales_db.* TO 'john'@'192.168.0.1';

Step 4Open the Firewall

⚠️ Admin privileges required

MySQL communicates on port 3306. Even when MySQL is listening on the network and the user exists, the server's firewall will drop remote traffic until you allow this port. The commands differ by firewall tool, so use the group that matches the one on your server. If your server runs in the cloud, check the provider's security group or network firewall as well. It can block port 3306 even when the server's own firewall is open.

Advertisement

For UFW (Ubuntu):

Permit access from one designated IP address. This is the safer choice.

🐧Bash / Shell
sudo ufw allow from 192.168.0.1 to any port 3306

Allowing connections from any IP works, but it is insecure. Use it only for short tests, and remove the rule afterwards.

🐧Bash / Shell
sudo ufw allow 3306/tcp

For iptables:

Permit access from one designated IP address:

🐧Bash / Shell
sudo iptables -A INPUT -s 192.168.0.1 -p tcp --destination-port 3306 -j ACCEPT

Allowing connections from any IP is insecure, so avoid it on a server that is reachable from the internet:

Advertisement
🐧Bash / Shell
sudo iptables -A INPUT -p tcp --destination-port 3306 -j ACCEPT

For FirewallD (Fedora/RHEL):

With this firewall tool, first create a dedicated network zone for database traffic:

🐧Bash / Shell
sudo firewall-cmd --new-zone=mysqlzone --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --permanent --zone=mysqlzone --add-source=192.168.0.1/32
sudo firewall-cmd --permanent --zone=mysqlzone --add-port=3306/tcp
sudo firewall-cmd --reload

Allowing connections from any IP is insecure, so avoid it on a server that is reachable from the internet:

🐧Bash / Shell
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload

Rules in some of these tools need to be reloaded, or saved, before they take effect or survive a reboot. Check the output of the commands above for any message about this.

Step 5Test Your Connection

Test the connection from the remote workstation, not from the server itself. A test from the server only proves the local connection works. The remote computer needs a MySQL client installed.

  1. Run the command below on the remote computer.
💻Code
mysql -u john -h 192.168.0.1 -p
  1. Replace john with the username you created and 192.168.0.1 with the address of the database server.
  2. Enter the password when prompted. You should arrive at the MySQL prompt on the remote server.

Troubleshooting

Remote connection failures usually have one of three causes: the firewall is blocking port 3306, the bind-address is wrong in the configuration file, or the database user has no permission for that client's IP address. Work through them in that order, checking the firewall rules, the network listener and the user account.

The likely root causes are:

  • Port 3306 is blocked by the firewall
  • MySQL is not listening on the right IP address

If the connection times out, the firewall is the usual cause. Check the server's firewall and any cloud security group first. If the connection is refused immediately, MySQL is probably not listening on the network address. Confirm the bind-address change was saved and that you restarted the service.

Error: "Host is not allowed to connect"

This error means the server was reached, but the user account has no permission for the client's IP address. An account created for one host does not work from another. Check that the host part of the account matches the IP address the client actually connects from. Then create the account again with the correct address, or add a second account for the new address.

Summary

To allow remote connections to a MySQL server, you edit the configuration file to change the bind address, restart the service, create a user with remote access, and open port 3306 in the firewall. Once all four are done, other computers and applications can connect to the database over the network.

  1. Edit the MySQL config file and change bind-address to 0.0.0.0
  2. Restart the MySQL service
  3. Create a new MySQL user with a specific IP address
  4. Give that user permission to access your database
  5. Open port 3306 in your firewall
  6. Test the connection from the remote computer

You need administrator rights for all of these steps. If connections drop or fail unexpectedly, check the IP binding and the firewall rules first. Where you can, limit access to specific IP addresses rather than opening the server to everyone.

Was this guide helpful?

0% of readers found this helpful (1 votes)

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Allow Apps Through Microsoft Defender Firewall in Windows 11
Windows How to Allow Apps Through Microsoft Defender Firewall in Windows 11
How to Open Windows Terminal as Admin Automatically
Windows How to Open Windows Terminal as Admin Automatically
How to Secure Your Data with Cipher on Windows 11
Windows How to Secure Your Data with Cipher on Windows 11
Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide
Ubuntu Linux Install MySQL and MariaDB on Ubuntu: A Step-by-Step Guide

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *