• I have updated WordPress in several webshops (wordpress, woocommerce)running on one vps server. I get this error on all webshop after updating:

    Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/vhosts/xxxx.nl/httpdocs/wp-includes/wp-db.php on line 1489

    It is quite a problem,
    Anybody an idea about the solution?

    Thanks!

    Auke.

Viewing 15 replies - 1 through 15 (of 15 total)
  • On the reported line in /wp-includes/wp-db.php (Line 1489 in WordPress v 4.5) the code reads:

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

    The issue goes away by adding a ‘@’ in front. So the code should read:

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

    Add the missing ‘@’, save and upload the modified file to get the warning to disappear. This adjustment worked for me.

    Hello,

    In my case it was PHP not being able to find where mysql.sock is when trying to connect to mysql.

    My environment which I encountered the problem was
    Clean install OSX 10.11 El Capitan + stock php enabled.
    mysql installed with home brew

    I had to make php.ini then I set mysql.default_socket as follows:

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

    Note: you can find out where your php searches for the mysql.sock with the phpinfo() command.

    Hope it helps.

    Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /wp-includes/wp-db.php on line 1489

    If this line is put into the google.com search engine, you will notice that many websites are displaying the warning message at the top of their HOME page, breaking the display. Google is picking that up as of April 17. This issue is widespread.

    In previous WP versions, file wp-db.php trapped the error and allowed either mysqli_real_connect() or @mysqli_real_connect() as needed. It is likely that a patch will be issued soon.

    additional note:
    after installation of WordPress, as soon as I enabled debug mode one, I got

    Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/vhosts/xxxx.nl/httpdocs/wp-includes/wp-db.php on line 1489

    and a couple of deprecation notices.

    I worked around by modifying the followings to my wp_config.php

    /** MySQL hostname */
    define('DB_HOST', 'localhost:/tmp/mysql.sock');

    Forgot to mention about my current environment :
    OSX El Capitan
    Server version: Apache/2.4.18 (Unix)
    PHP 5.5.31 (Stock)
    mysql Ver 14.14 Distrib 5.7.12, for osx10.11 (x86_64) installed with home brew which has a different mysql.sock file location than that expected by the apache / php.

    Thanks @nelsonmct, your example work.

    I’ve had the same problem but it’s been sporadic. Too many plugins to pinpoint what could be causing it. Have to reboot every few hours.

    This is what I’ve been getting for wp-admin page.

    Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/html/wp-includes/wp-db.php on line 1489
    
    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/html/wp-includes/wp-db.php on line 1515
    
    Warning: mysql_connect(): No such file or directory in /var/www/html/wp-includes/wp-db.php on line 1515
    
    Error establishing a database connection

    I’ve added the “@” in front of mysqli_real_connect() in /wp-includes/wp-db.php on line 1489 and it seems to be fine right now.

    I believe the Deprecated: mysql_connect(): comes from using too high a PHP version for some of your plugins. Roll the version back to 5.3.x and the deprecated warnings will disappear. That might not be the best approach if the site is using newer PHP coding.

    WordPress recommends PHP v5.6. So the wp-db.php file definitely should not be using mysql_connect. See https://www.ads-software.com/about/requirements/

    I am using PHP v5.5 with no issues, but I see that Line 1515 in wp_dp.php is in an if { } else { } set. My site might not be hitting the else condition. You might try replacing mysql_connect with mysql_real_connect to see if the Line 1515 warning disappears. That has worked for me with other CMS services.

    I have since a few days:
    [13-Apr-2016 22:27:58 UTC] PHP Warning: Error while sending QUERY packet. PID=16626 in xxxx/wp-includes/wp-db.php on line 1803

    Could this be somehow related to your problems?

    Adding the “@” doesn’t fix my problem just FYI. I’ve disabled a few plugins and now the problem is no more. So a solution is to try and start disabling plugins until you find the bad plugin(s).

    Try to change define(‘DB_HOST’, ‘localhost’); to define(‘DB_HOST’, ‘127.0.0.1’); in wp-config.php.
    It works for me!!!!

    Check your WP CLI version.

    Hi guys please can you assist.I am trying to migrate my website to wordpress in localhost.I am using HTML Import to do this.So it compiles for a while and then I recieve numerous errors saying Warning: mysqli_query(): MySQL server has gone away in C:\wamp\www\wordpress\wp-includes\wp-db.php on line 1811

    Hi guys, not sure if this topic is still alive but as of recently (last 3 days) I’ve been getting this same error on my new site.

    To be specific it’s this error
    mysqli_real_connect(): (HY000/2002): No such file or directory in /home/go4digit/public_html/wp-includes/wp-db.php on line 1490

    and this one

    mysql_connect(): No such file or directory in /home/go4digit/public_html/wp-includes/wp-db.php on line 1520

    Thing is, when I check those lines there is only this:

    line 1490: $message .= ‘<p>’ . sprintf(

    as a part of this

    $message .= “

      \n”;
      $message .= ‘

    • ‘ . __( ‘Are you sure that the database server is running?’ ) . “
    • \n”;
      $message .= ‘

    • ‘ . __( ‘Are you sure that the database server is not under particularly heavy load?’ ) . “
    • \n”;
      $message .= “

    \n”;

    $message .= ‘<p>’ . sprintf(
    /* translators: %s: support forums URL */

    also, line 1520: * Some queries are made before the plugins have been loaded,

    as a part of this

    * Filter the database query.
    *
    * Some queries are made before the plugins have been loaded,
    * and thus cannot be filtered with this method.
    *
    * @since 2.1.0
    *
    * @param string $query Database query.
    */

    I don’t know much about WordPress, so I don’t know what to do here.
    Can you guys help please?

    Also, so far I’ve had a successful connect to database (error that first pops up on homepage) so DB name, username, password and host are fine. I’ve pressed the repair database in cPanel and it says repaired but nothing changes.

    Any help would be much appreciated!
    Thanks!

    Had this problem.
    I used php-fpm with chroot.
    If host name is localhost then mysqli tries to use socket, not port.
    But if you chroot your PHP then mysqli can’t find socket where it should be.
    MySQL socket is usually /tmp/mysql.sock.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘mysqli_real_connect(): (HY000/2002): No such file or directory’ is closed to new replies.