Link to home
Start Free TrialLog in
Avatar of Bharpinder Singh
Bharpinder Singh

asked on

mysqli_real_connect(): (HY000/2002): Connection refused

Hello,

I am getting following error while starting phpmyadmin.

 MySQL said: Documentation
#2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured).
mysqli_real_connect(): (HY000/2002): Connection refused
Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/2002): Connection refused
Avatar of arnold
arnold
Flag of United States of America image

The error is fairly clear.
Since you have not posted the connection string, the only thing I can suggest is on the server where this web site is, try connection to the server referenced in the string on port 3306.
If you can connect to port 3306, double check the connection string you use actually works with the MySQL client.
I.e. If you define a user/password with access to a specific database, if your connection string does not specify a database, this user's connection attempt will be denied.

Note, testing while root is not the same as when the access is through the web which runs under different credentials. So you must account for that.
Where is the MySQL config store the socket connection? Settings in /etc/My.cnf....

I tried to cover the majority of possible places where you could look.
Avatar of Bharpinder Singh
Bharpinder Singh

ASKER

Port is correct in my.cnf file..
problem is occurring when system restarts.
Hi!

If you are restarting the mysql service and logged into the mysql server in the phpadmin
console then it is "working as designed". The time it takes to restart depends on how you configure your mysql server and it's memory consumption before and after restart and the current online workload of the server when restart occurs. While the restart is in progress connections are forced off and no new connections allowed until the mysql server is ready to accept connections.

Regards,
    Tomas Helgi
Hello Helgi,

i didn't get properly but how can i fix it?
Hi!

As I said before. This works as designed.
Only after the mysql server has restarted you can establish the connection again and you need to do it manually.

Regards,
     Tomas Helgi
Make sure MySQL is configured to auto start.


I
If you want MySQL to auto-start after a system restart / reboot, then the steps depend on what kind of system you're using. I'll cover the most common scenario for now, which is usually CentOS.

For Red Hat and CentOS and similar, you -probably- will have a "mysql" script in your /etc/init.d folder. It might be called "mysql" or "mysql.server" or something like that. You should have one already if you installed via a package of some kind, like yum or rpm. This is just a script to start/stop/restart the service, and in CentOS / Red Hat, you normally use the "chkconfig" utility to turn on/off these scripts:
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-services-chkconfig.html

So if you have a properly-formatted script called //etc/init.d/helloworld

...then you would enable it with:
chkconfig helloworld on

So figure out what your mysql script name is in /etc/init.d and then run chkconfig on it.

Now, this will ONLY work if you're actually on a CentOS / Red Hat or similar system that actually uses chkconfig, and also only if you have a properly-formatted init script. The script will define the "run levels" for the service, which tell the system when to run. If you're curious about the specifics, here's a simple and good article on it (or you can just Google for "run levels"):
https://www.liquidweb.com/kb/linux-runlevels-explained/

If you're using a different distribution of Linux, you might have a different want of auto-starting a service, so you would need to Google for instructions on how to properly configure your operating system to auto-start a service.
So sorry about that
i found this looking for this very same issue when trying to login through phpMyAdmin

the cause of this issue for me was primarily not having the ha_connect.so library loaded.

however it was ultimately cause by myself having recently upgraded to fedora 28 and not having installed the mariadb-connect-engine package
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.