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

SomeNorwegianGuy picture SomeNorwegianGuy · Sep 27, 2015 · Viewed 53.6k times · Source

I'm trying to run PHPUnit to unittest a WordPress plugin, but the error in the title keeps showing up.

I used WP-CLI to setup the unittests, but also WP-CLI throws a similar error when I try to run it.

I use MAMP to run the database.

I have setup WP-CLI and PHPUnit as phars, that are aliased in ~/.bash-profile, and ran with the default "php" supplied by OS X. Changing this, and running WP-CLI and PHPUnit with the latest PHP version supplied by MAMP fixed WP-CLI(It was running and connecting to the database just fine) but PHPUnit was still throwing the same error.

I have tried editing the wp-config.php file, and setting the host to ":/path/to/mamp/mysql.socket", "localhost:/path/to/mamp/mysql.socket" and "127.0.0.1", none of which helped.

I'm totally stuck, and don't know what to try next.

Answer

Doug Thompson picture Doug Thompson · Dec 12, 2015

I just ran into this error - have you checked the schema exists that your wp-config.php is specifying?

In my case I'd outright forgotten to create it, so the fix was as simple as a CREATE DATABASE wordpress.

I've also run into this error when the wp-config.php database host is wrong (try swapping localhost and 127.0.0.1).