June 16, 2020
June 16, 2020
In this article, you will learn how to allow remote connections to MySQL on an RHEL/CentOS server or VPS. This way, you can manage your MySQL database from a distant location, such as your home. However, you need to complete the following steps when you are connected to a local network.
Upgrade your VPS Hosting and save up to 55% with a 30-day money-back guarantee!
Before we begin this guide, you have to know how to establish an SSH connection using PuTTY (Windows) or built-in terminal shell (Linux, macOS). Also, since you will change your MySQL configuration, you need to have root access to the server. If you are a Hostinger VPS user, you can find the login details on hPanel’s Server tab.
By default, MySQL is not listening for external connections. You need to change that by adding an extra option in the configuration file. Here are the steps:
mysql --help | grep "Default options" -A 1
The output should look like this:
Note that you have to replace YOUR.SERVER.IP with your actual dedicated IP address.
systemctl restart mysqld
iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
Alternatively, you can grant access to just one IP:
iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT
Don’t forget to change 10.5.1.3 in this example to your real IP address.
service iptables save
You should receive this response:
All is set. From now on, your server will allow remote connections to your MySQL database.
In this tutorial, you have learned how to allow remote connections to MySQL. By doing this, you can now access your server’s database even when you are not connected to a local network. To summarize, let’s overview the steps once again:
Good luck, and be sure to comment below if you have any questions!