How to Enable Remote Access to Your MariaDB/MySQL Database on Ubuntu
Enabling remote access to your MariaDB or MySQL database is essential for accessing your database from another server or application. This guide walks you through configuring your MariaDB/MySQL instance for remote access manually via the command line.
Prerequisites
Before you begin, ensure you have the following:
- Shell (SSH) access to your VPS.
- Familiarity with basic Linux commands.
Step 1: Verify MariaDB Server
- Make sure the MariaDB server is running. Run the following command:bashCopyEdit
$ ps -ef | grep -i mysql
Example output:bashCopyEditmysql 595 1 0 04:17 ? 00:00:00 /usr/sbin/mysqld root 1350 1337 0 04:22 pts/0 00:00:00 grep --color=auto -i mysql
- Check if MariaDB is listening on
localhost
:bashCopyEdit$ netstat -ant | grep 3306
Example output:bashCopyEdittcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
Step 2: Configure MariaDB for Remote Access
MariaDB is configured to deny connections from remote servers by default. Follow these steps to allow remote connections:
- Edit the Configuration FileLocate and edit the MariaDB configuration file to update the
bind-address
directive. Use one of the following commands:bashCopyEdit$ nano /etc/mysql/my.cnf
orbashCopyEdit$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Update the
bind-address
Find thebind-address
directive and change its value from127.0.0.1
to0.0.0.0
:confCopyEditbind-address = 0.0.0.0
- Save and Restart MariaDBSave the changes and restart the MariaDB service to apply them:bashCopyEdit
$ sudo systemctl restart mariadb
Step 3: Verify the Changes
Check the listening status of MariaDB again to confirm the update:
bashCopyEdit$ netstat -ant | grep 3306
Expected output:
bashCopyEdittcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
This confirms that MariaDB is now listening on all available IP addresses.
Conclusion
You’ve successfully enabled remote access to your MariaDB/MySQL database. You can now connect to the database from a remote server or application. For enhanced security, remember to:
- Configure a strong password for your database user.
- Use a firewall to allow connections only from trusted IP addresses.
Responses