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:
1sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Locate the line containing
bind-addressand change it to:1bind-address = 0.0.0.0
Save the changes and restart MariaDB:1sudo service mariadb restart
- Next, open port 3306 in UFW (Uncomplicated Firewall) with the following commands:
1sudo ufw allow 3306/tcp sudo ufw reload
- Create a new user specifically for remote access in MariaDB:
12CREATE USER 'remoteusername'@'%' IDENTIFIED BY 'insert-password-here';FLUSH PRIVILEGES;
- To grant remote access to a specific database, run this command:
1GRANT ALL PRIVILEGES ON databasename.* TO 'remoteusername'@'%';
If you want to allow remote access to all databases, use the following command:1GRANT 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.