This guide demonstrates how to enable remote connections to the MySQL/MariaDB server on Ubuntu 18.04. By default, Ubuntu MySQL Server blocks all remote connections, preventing external access to the database server.
To allow remote connections to MySQL on an Ubuntu server, you need to modify the MySQL main configuration file.
If you have installed the MySQL Database server, the configuration file is located at :/etc/mysql/mysql.conf.d/mysqld.cnf
.
If you are using the MariaDB Database server, the configuration file is located at: /etc/mysql/mariadb.conf.d/50-server.cnf
.
Steps:
Edit the Configuration File:
Modify the bind-address:
- Under the
[mysqld]
section, find the line:
bind-address = 127.0.0.1
- Change this line to:
bind-address = 0.0.0.0
By setting the value to 0.0.0.0
, MySQL is instructed to bind to all available interfaces, allowing remote connections to the MySQL Server on Ubuntu 18.04.
Save the Changes and Restart the Server:
Verify MySQL Server is Listening on 0.0.0.0:3306:
For MySQL:
sudo netstat -tulnp | grep mysqld
For MariaDB:
sudo netstat -tulnp | grep mariadb
You should see output indicating that MariaDB is listening on the expected socket if it is installed on your VPS.
If UFW is Enabled on the Server
If the UFW firewall is enabled on your VPS, it will block MySQL remote access. You need to add a firewall rule to open port 3306:
sudo ufw allow 3306/tcp
Note: Enabling remote connections to your MySQL server can pose security risks. Avoid exposing your database server to the outside world unless absolutely necessary, especially in a production environment.