Had this problem a number of times on our setup, so I've made a check list.
This assumes you want phpMyAdmin connecting locally to MySQL using a UNIX socket rather than TCP/IP.
UNIX sockets should be slightly faster as they have less overhead and can be more secure as they can only be accessed locally.
Service
- Is the mysqld service running?
service mysqld status
- .. If not
service mysqld start
- Has config has changed since service started?
service mysqld restart
MySQL Config (my.cnf)
- Check that there isn't a non-socket client protocol set, e.g.
protocol=tcp
- Check that the socket location is accessible and has the right permissions
PHP Config (php.ini)
If you can connect locally from the command line, but not from phpMyAdmin, and the socket file is not in the default location:
- Set the mysqli default sockets to the new location:
mysqli.default_socket = *location*
- ... I also set the
pdo_myql.default_socket
and mysql.default_socket
just to be sure
- Restart your web service (httpd in my case)
service httpd restart
phpMyAdmin Config (config.inc.php)
- Check that the host is set to localhost:
$cfg['Servers'][$i]['host'] = 'localhost';
- The socket location can also be set here:
$cfg['Servers'][$i]['socket'] = '*location*';
N.B.
As pointed out by @chk; Setting the $cfg['Servers'][$i]['host']
from localhost
to 127.0.0.1
just causes the connection to use TCP/IP rather than using the socket and is more of a workaround than a solution.
The MySQL config setting bind-address=
also only affects TCP/IP connections.
If you don't need remote connections, it is recommended to turn off TCP/IP listening with skip-networking
.