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.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF