Bobcares

cPanel MySQL Connection Refused: How to Fix?

by | Aug 31, 2022

Let us take a closer look at the CPanel MySQL connection refused error and its remedies with the support of our MySQL support services at Bobcares.

Enable Remote MySQL from WHM

Remote MySQL connections are disabled by default in cPanel servers to avoid potential security risks to the MySQL server.

cpanel mysql connection refused

We can activate them via Web Host Manager (WHM) or cPanel (for specific databases created under that cPanel account). Make sure that port 3306 is open in the server firewall before proceeding with the next methods.

  1. Log into WHM, navigate to the SQL Services panel, and then click the Additional MySQL Access Hosts option.
  2. At the next screen, enter IP address or host(s) that we wish to grant remote MySQL access to and click the Save button. If we want to activate these settings for all cPanel accounts, click on Click Here link at bottom.

    Now, the remote connection will be in the active stage in WHM. Each cPanel account that wants to use a remote connection needs to activate it as follows.

Enable Remote MySQL from cPanel for connection refused error

  1. Navigate to the Databases area of cPanel. Locate and select the Remote MySQL option under the Databases section.
  2. On the next screen, enter the hostname or IP address to which we want to grant remote MySQL access and click the Save button.

    If the IP address changes frequently, use the % sign as a wildcard. This includes all IP addresses in that range. For example, 192.168.3.% can list IP addresses spanning from 192.168.3.1 to 192.168.3.255.

It was occasionally not available remotely after permitting MySQL remote connections since it was bound to localhost (127.0.0.1).

Make the following modifications to the MySQL configuration file to address this (my.conf).

  1. Firstly, login to MySQL server and using a text editor configure my.cnf file such as vi. The, my.cnf file will be present at:

    /etc/mysql/my.cnf or at /etc/my.cnf.
    # vi /etc/my.cnf

  2. After opening a file, look for the line that contains skip-networking and make sure the comment is as follows:

    # skip-networking

  3. After that, find the line that contains bind-address and comment it out as follows:

    # bind-address = 127.0.0.1

  4. Finally, Save the file, then close it and restart the MySQL server.

    # /etc/init.d/mysql restart //  Debian & Ubuntu Linux
    # /etc/init.d/mysqld restart // CentOS & Fedora Linux

Fix the cPanel Mysql error Connection refused

SQLSTATE[HY000] [2002] cPanel MySQL Connection refused on the MySQL server. can be caused by a number of factors; however, if we follow the procedures below, we should be able to resolve/fix the error:

  • Check that the [database] section of the config file config/config.ini.php (in the Matomo directory) contains the right and up-to-date Database credentials.

    Verify that the database username, password, database host, and database port are all valid.

  • If the config file refers to host = “localhost,” we can try changing it to 127.0.0.1, for example, in the config.ini.php under [database] put host = “127.0.0.1.”
  • If the aforementioned modifications do not cure the problem, try connecting to MySQL from the command line to see if the credentials are right and the server is operational.

    Connect to the Matomo server and run the following command: -h [hostname] -u [username] -p[password] -D [dbname] mysql (Replace the values in [] with the ones from the config.ini.php file.).

  • If the above command runs but we still get the “Connection rejected” error in the browser, there may be a PHP problem. Please contact the web hosting provider or system administrator.
  • Make sure that the MySQL Server is up and functioning. Connect to the MySQL database server and perform the command mysqladmin -u root -p status to see if the MySQL server is active.

    The result should look like this: 172505 hours of uptime Questions: 90 Threads: 2 0 slow queries 157 open tables 3 flush tables There are 76 open tables.

  • If the database server is not running, then restart Mysql (or rebooting the whole server).
  • Alternatively, if the database server has run out of disk space and there is no more space available on the server, it may begin to refuse connections.
  • Sometimes MySQL servers can refuse some connections according to the configurations (for example connections from outside the network).

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude we have now learned more about the cPanel MySQL connection refused error and how to manage and avoid it with a set of simple steps begging from Database credential checking and many more with the support of our MySQL support services. 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.