To prevent potential security risks to MySQL servers, by default, remote MySQL connections are disabled in cPanel servers. Remote MySQL connections can be allowed through Web Host Manager (WHM) or cPanel (for specific databases created under that cPanel account). Since we do not allow remote MySQL connections in cPanel shared hosting, this guide will be only applicable to our VPS and dedicated server customers. Before you check out the following methods, ensure that port 3306 is opened in your server firewall.
Enable Remote MySQL from WHM
1. Log in to WHM.
2. Locate the SQL Services section and click the Additional MySQL Access Hosts link.
3. At the next screen, enter the IP address or host(s) you wish to grant remote MySQL access and click the Save button. If you want to activate these settings for all cPanel accounts, click the Click Here link at the bottom. Now, the remote connection has been activated in WHM. Each cPanel account that wants to use a remote connection needs to activate it as follows.
Enable Remote MySQL from cPanel
1. Log in to cPanel. Please refer to how to login to cPanel from WHM for more details.
2. Locate the Databases section. Under the Databases section, locate the Remote MySQL option and click on it.
3. In the next screen, enter the hostname or IP address you want to grant remote MySQL access and click the Save button. If your IP address changes regularly, you can use a wildcard using the % symbol. This 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.%.
NOTE: Following steps are additional and need to be taken only when you are unable to connect to the MySQL server after enabling Remote MySQL from WHM.
Sometimes, after enabling MySQL remote connections, it could not get accessed remotely because it might be bound on localhost (127.0.0.1). To fix this, you'll need to make the following changes in the MySQL configuration file (my.conf).
1. Log in to the MySQL server (where MySQL server is installed) and edit my.cnf file using a text editor such as vi. Usually, my.cnf file is located at /etc/mysql/my.cnf or at /etc/my.cnf
# vi /etc/my.cnf
2. Once a file is opened, locate the line that contains skip-networking and make sure that it is commented as follows.
# skip-networking
3. Now locate the line containing the bind-address and comment it out as follows.
# bind-address = 127.0.0.1
4. Save and Close the file and restart the MySQL server.
# /etc/init.d/mysql restart // Debian & Ubuntu Linux
# /etc/init.d/mysqld restart // CentOS & Fedora Linux
→ Looking to connect MySQL DB from phpMyAdmin? Please refer to connect MySQL from phpMyAdmin for more details.