In this tutorial, we will discuss how to enable remote access to MariaDB, which can also be applied to MySQL by referencing the correct file path and name. This allows you to access the database from another server or desktop application on Windows or macOS.
- Start by modifying the MariaDB configuration file:
12345sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Locate the line containing
bind-address
and change it to:12345bind-address = 0.0.0.0Save the changes and restart MariaDB:
12345sudo service mariadb restart
- Next, open port 3306 in UFW (Uncomplicated Firewall) with the following commands:
123456sudo ufw allow 3306/tcpsudo ufw reload
- Create a new user specifically for remote access in MariaDB:
123456CREATE USER 'remoteusername'@'%' IDENTIFIED BY 'insert-password-here';FLUSH PRIVILEGES;
- To grant remote access to a specific database, run this command:
12345GRANT ALL PRIVILEGES ON databasename.* TO 'remoteusername'@'%';
If you want to allow remote access to all databases, use the following command:
12345GRANT ALL PRIVILEGES ON *.* TO 'remoteusername'@'%';
Keep in mind that enabling remote database connections comes with security risks. Proceed with caution.
This information should prove beneficial for configuring remote access to your MariaDB database.