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 );

  • Which version of WordPress you're using ? – Abdul Awal Uzzal Apr 27 '17 at 21:36

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.

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket

; 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

; 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

The error messages show signs of mismatch between your wordpress version and your PHP (or even mysql) version. Sounds like you are trying to run old wordpress version on new php version, or that you do not have mysqli extension of PHP active.

This will explain the last two errors, but not the first one. The first one seems to be a sign that either mysql and its relevant drivers are misconfigured or that the mysql just shutsdown from time to time.

If you are on a shared hosting, call their support, if it is your own VPS you need to get someone to check out your setup (assuming you have enough memory to handle your load).


Try to replace your current host from localhost to in your wp-config.php. If you can then try to restart your MYSQL services.


Try using the IP address of your local server instead of localhost. That means set at DB_HOST in wp-config.php. So the full thing will be like-

/** MySQL hostname */
define('DB_HOST', '');

Check those below answers for more information-




In Wordpress I was having a problem between mysqli and PDO. I solved it with the command yum update & yum upgrade, no centos and he gave me the following updates:

================================================== ==============================  Package Arch Version Repository Size ================================================== ============================== Installing:  lsphp73-mysqlnd x86_64 7.3.15-1.el7 litespeed 132 k      replacing lsphp73-mysqlnd.x86_64 7.3.14-1.el7 Updating:  lsphp73 x86_64 7.3.15-1.el7 litespeed 5.0 M  lsphp73-bcmath x86_64 7.3.15-1.el7 litespeed 27 k  lsphp73-common x86_64 7.3.15-1.el7 litespeed 650 k  lsphp73-gd x86_64 7.3.15-1.el7 litespeed 114 k  lsphp73-imap x86_64 7.3.15-1.el7 litespeed 32k  lsphp73-mbstring x86_64 7.3.15-1.el7 litespeed 559 k  lsphp73-opcache x86_64 7.3.15-1.el7 litespeed 191 k  lsphp73-pdo x86_64 7.3.15-1.el7 litespeed 67 k  lsphp73-process x86_64 7.3.15-1.el7 litespeed 29 k  lsphp73-soap x86_64 7.3.15-1.el7 litespeed 120 k  lsphp73-xml x86_64 7.3.15-1.el7 litespeed 126 k  openlitespeed x86_64 1.6.9-1.el7 litespeed 37 M

Transaction Summary ================================================== ============================== Install 1 Package Upgrade 12 Packages

Total download size: 44 M Downloading packages: No Presto metadata available for litespeed

Total 13 MB / s | 44 MB 00:03

Besides that mine  fastcgi_pass unix: /var/php-nginx/15822663384347.sock/socket;

It was causing conflict.

but it still didn't solve the problem.

The solution found was to change the username and password in the file that connects the cms with the database and I saw that suddenly it could be the username that has a dot or is the same domain name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.