This guide explains how to allow remote connections to a MySQL/MariaDB server on Ubuntu 18.04. By default, Ubuntu's MySQL Server blocks all remote connections, preventing external access to the database server.
To enable remote connections, you'll need to modify the MySQL main configuration file.
If you have installed MySQL, the configuration file is located at : /etc/mysql/mysql.conf.d/mysqld.cnf
For MariaDB, the configuration file is: /etc/mysql/mariadb.conf.d/50-server.cnf
Steps:
1.Open the Configuration File:
1.1 For MySQL:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
1.2 For MariaDB:
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
2. Modify the Bind Address:
2.1 Find the line under the [mysqld] section:

2.1 Change it to:

This change tells MySQL to listen on all available network interfaces, thereby allowing remote connections.
3. Save and Restart the Database Server:
3.1 For MySQL:
sudo systemctl restart mysql
3.2 For MariaDB:
sudo systemctl restart mariadb
4.Verify the Server is Listening on the Correct Port:
4.1 For MySQL:
sudo netstat -tulnp | grep mysqld
4.2 For MariaDB:
sudo netstat -tulnp | grep mariadb
You should see the server listening on 0.0.0.0:3306.

5. Adjust Firewall Rules (if UFW is enabled):
If UFW (Uncomplicated Firewall) is enabled on your server, it will block MySQL remote access by default. You need to open port 3306:
sudo ufw allow 3306/tcp
Important Note:
Enabling remote connections to your MySQL server can pose a security risk, especially in a production environment. Only expose your database server to external connections if absolutely necessary.