Error establishing a database connection – with Debug Data

I had this same error. For me, this happened because I moved the datadir of my database.

On centos
– the default location of the datadir is /var/lib/mysql
– and the default loc of the socket file is /var/lib/mysql/mysql.sock

I moved the datadir to /datadir/mysql. The Mysql db server started fine and the ‘mysql’ command line client worked fine.

However, when I started apache and then accessed my wordpress site, I got that error.

The fix was to update /etc/php.ini.

There are three settings in that file for the mysql.sock location for:
– pdo
– mysql
– mysqli

Below are the changes I made for those three settings – to set each one to “/datadir/mysql/mysql.sock”. Prior to my change, all three were just blank after the ‘=’, and so the default location was used.

[Pdo_mysql]
  ...
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=/datadir/mysql/mysql.sock


 [MySQL]
  ...
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket = /datadir/mysql/mysql.sock


[MySQLi]
  ...
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysqli.default-socket
mysqli.default_socket = /datadir/mysql/mysql.sock