Cannot connect to the database: SQLSTATE[HY000] [2002] Connection refused

I am getting database connection error message, as below:
Cannot connect to the database:

SQLSTATE[HY000] [2002] Connection refused

However my database configuration is correct in the configuration file. Matomo was working fine, but now getting this error, can not find much in log file. I am using latest version of Matomo with MySQL on Debian 9. URL: https://analytics.bluella.in/analytics/

Hi,

The error says that PHP can’t connect to the MySQL instance, so there is little Matomo can do.

You could try out different settings in config/config.ini.php and e.g. try to replace localhost with 127.0.0.1 or the other way round.

Thanks for replying !!

I tried those settings, I did changes in the config file, also was able to login via shell using the same db credentials. Currently the site started working now. But still I am searching for the root cause.

We have published a FAQ about the error “Connection refused”, here it is: How do I fix the Mysql error “Connection refused”?

Hope it helps