0

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 Apr 27 '17 at 21:36
0

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

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

Check those below answers for more information-

https://stackoverflow.com/questions/13769504/mysqlimysqli-hy000-2002-cant-connect-to-local-mysql-server-through-sock

https://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi

0

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

0

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
0

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

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.