Error establishing a database connection – with Debug Data

my site started acting up a few days ago, running the debug I get these lines.

Tried to mess around with the DB but couldn’t get my head through it.

Do you have any idea what those lines imply?

Warning: mysqli_real_connect(): (HY000/2002): Can’t connect to local
MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2 “No such
file or directory”) in
/home/u420302506/public_html/wp-includes/wp-db.php on line 1490

Deprecated: mysql_connect(): The mysql extension is deprecated and
will be removed in the future: use mysqli or PDO instead in
/home/u420302506/public_html/wp-includes/wp-db.php on line 1520

Warning: mysql_connect(): Can’t connect to local MySQL server through
socket ‘/var/lib/mysql/mysql.sock’ (2 “No such file or directory”) in
/home/u420302506/public_html/wp-includes/wp-db.php on line 1520

Line 1490:

mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );

Line 1520:

this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );

5 Answers
5

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

Leave a Comment