Remote MySQL connections are disabled on WHM/cPanel servers by default to prevent potential security risks to MySQL servers. Remote MySQL connections can be allowed from Web Host Manager (WHM) or through cPanel (for specific databases created under that cPanel account). This guide will be applicable to VPS and dedicated server customers as remote MySQL connection is not allowed in shared hosting by hosting providers. Before you allow remote connection to MySQL server in cPanel/WHM server, please ensure to open port 3306 on your server firewall.
Enable Remote MySQL from WHM
- Login to WHM.
- Locate theSQL Services section and click Additional MySQL Access Hosts link.
At the next screen, enter an IP address or host(s) you wish to grant remote MySQL access and click the Save button. To activate these settings for all cPanel accounts, click the Save at the bottom. Now, a remote connection is activated in the WHM panel. Each cPanel account that wants to use a remote connection needs to activate this.
Enable Remote MySQL from the cPanel
- Login to cPanel.
- Locate the Databases section and locate Remote MySQL option and click on it.
- In the next screen, enter the hostname or IP address, you need to grant remote MySQL access and click the Save button. If your IP address changes regularly, you can use a wildcard by using the % symbol. It will add all IP addresses in that range. For example; if you want to list IP addresses ranging from 192.168.3.1 to 192.168.3.255, you can add an IP address as 192.168.3.%.
Above steps will allow remote connection to MySQL Server from cPanel/WHM server.
NOTE: Below are the additional steps that need to be taken if you cannot connect to the MySQL server after enabling Remote MySQL from WHM.
Sometimes, after enabling MySQL remote connections, you might not be able to connect to the MySQL server remotely. This happens as the MySQL server is bound on localhost (127.0.0.1). To fix this issue, you need to make the following changes in the MySQL configuration file (my.conf).
- Login to the MySQL server (where MySQL server is installed) and edit my.cnf file using a text editor such as a vi editor. Usually, my.cnf file is located at /etc/mysql/my.cnf or at /etc/my.cnf.
# vi /etc/my.cnf
- Once the file is open, locate the line containing skip-networking and ensure it is commented as below.
- Now locate the line containing bind-address and comment it out as follows.
# bind-address = 127.0.0.1
- Save and Close the file and restart the MySQL server using the below command.
# /etc/init.d/mysql restart // Debian & Ubuntu Linux
# /etc/init.d/mysqld restart // CentOS & Fedora Linux
You should now be able to connect to the MySQL server remotely.