Introduction to Mat Wright

Mat Wright is a Zend Certified Engineer and qualified designer available for freelance web development + consultation work.

Saturday, February 13, 2010

phpMyAdmin Error Code 2002

If you've stumbled across this page via a search engine then you've probably just spent the last couple of hours going round in circles with the phpMyAdmin config file or set-up script - you've added the correct hostname, the socket appears to be correct (usually /var/lib/mysql/mysql.sock) but every time you try and log in you get the message:

#2002 – The server is not responding (or local MySQL server’s socket is not correctly configured)

If you are at the end of your tether, go straight to the quick fix otherwise carry on reading.

Check List

The first think to check is obviously that the mysql daemon is definately running, the quickest way to do this is to simply use the mysqladmin ping command:

#mysqladmin ping

and you should see:

mysqld is alive

If you don't see the above (mysqld is alive) then you need to start the mysql daemon:


With confirmation that mysqld is running you now need to make sure that you have entered the correct host, port and socket in the config file or set-up script.

The host is usually localhost however this may be different depending how you have your server setup, if you are connecting to a remote server then the host is the name of the server you are connecting to.  You can check the hostname by looking at the command line prompt whilst logged into the server where mysql is hosted :




In the examples above, your hostname would be either localhost or

The port is usually 3306 and the socket is usually /var/mysql/mysql.sock.

You can check both the port and socket using the following command:

#mysqladmin variables

This will list of of your mysql variables in alphabetical order, just scroll down to port to find out the port number and socket to confirm the socket.

Finally check you have the connection type tcp or socket. The default is tcp however some servers allow socket only connections for tightened security.
Check in the variables obtained above for skip_networking, if this is set to ON then you must set the connection type to socket otherwise leave it as tcp.

If you have checked all of the above and you are still getting the error then proceed to the quickfix below where you will find details about a common cause of this problem.

Quick Fix 

Providing mysqld is running and phpmyadmin is correctly configured (see checklist above) the issue is most likely to be the following:

A symbolic link to the socket must be created in your server's temporary directory.

The temporary directory is usually /tmp however you can double check this within your mysql variables by issuing the following command:

#mysqladmin variables

Scroll down to tmpdir to find the temporary directory that mysql uses, you may also wish to re-confirm the socket path too which is listed under socket within the variable list - the default is /var/mysql/mysql.sock.

To create the symbolic link, issue the following command:

#ln -s /var/mysql/mysql.sock /tmp

Note : Don't forget to replace /var/mysql/mysql.sock with your socket path and /tmp with your temporary directory, the above example uses the default settings.

Restart mysqld.

/etc/init.d/mysqld restart

Note : Debian and Ubuntu users should type mysql instead of mysqld.

You should now be able to log into phpMyAdmin.

No comments:

Post a Comment