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

I am trying to run PHPUnit to remove the WordPress plugin, but the error in the header continues to be displayed.

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

I use MAMP to start the database.

I have WP-CLI and PHPUnit as phars, which are smoothed in the ~ / .bash profile and run with the default "php" provided by OS X. By changing this and launching WP-CLI and PHPUnit with the latest version of PHP supplied by fixed WP -CLI from MAMP (it worked and connected very well to the database), but PHPUnit still threw the same error.

I tried to edit the wp-config.php file and set the host to ": /path/to/mamp/mysql.socket", "localhost: /path/to/mamp/mysql.socket" and "127.0.0.1", not a single one of which did not help.

I am completely stuck and do not know what to try next.

+5
source share
7 answers

I just ran into this error - did you check if the schema pointed to by wp-config.php exists?

In my case, I completely forgot to create it, so the fix was as simple as CREATE DATABASE wordpress .

I also encountered this error when the database host wp-config.php is wrong (try replacing localhost and 127.0.0.1 ).

+12
source

First, make sure MySql is actually running. It will not create a socket file if the process is not running.

 netstat -tulpn | grep mysql 

or

 ps -e | grep mysql 

If MySql is running, changing the database host from localhost to 127.0.0.1 in wp-config.php works, but this is only a workaround.

When you specify localhost , the mysqli_real_connect() function tries to connect to your database via a Unix socket that it cannot find (hence the error "there is no such file.") When you specify 127.0.0.1 , it tries to connect to its database using The default TCP port (usually 3306), which works.

This does not fix the problem that PHP does not know where to find your MySql socket. You need to configure the following parameters in php.ini . The location in the socket will depend on your OS, but you can usually find it by running locate mysql.sock . Here are the settings that work for me on CentOS 6.8.

php.ini

 pdo_mysql.default_socket = /var/lib/mysql/mysql.sock mysqli.default_socket = /var/lib/mysql/mysql.sock 

Other systems typically use /tmp/mysqld.sock . You can check the configured location by checking the MySql my.cfg configuration file.

After you have configured PHP to indicate the correct location of the sockets, restart Apache / nginx so that it picks up the new settings.

Now you can use localhost as intended.

+5
source

Just go into your phpMyAdmin, click on your database and copy the ip where the service is running, and replace the wp-config.php file:

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

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

Replace localhost on mysql startup ip

0
source

It embarrassed me, but I decided in the end.

My MySQL port is 3308, so I change "127.0.0.1" to "localhost: 3308" in

 $cfg['Servers'][$i]['host']. 

It is working!

In addition, I installed

 $cfg['Servers'][$i]['controluser'] = ''; $cfg['Servers'][$i]['controlpass'] = ''; 

And...

 $cfg['Servers'][$i]['auth_type'] = 'cookie'; 

But I think the most important is port change.

0
source

Make sure you do not have the same table prefix with a different database

0
source

I could be fixed using localhost and 127.0.0.1 changes in wp-config.php

also set define('WP_DEBUG', false); It would be a good suggestion to hide such problems. Since I could see the next wp-db.php

 if ( WP_DEBUG ) { mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } else { @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } 
-1
source

In the report 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 problem disappears by adding @ in front. Therefore, the code should look like this:

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

Add the missing @ , save and load the modified file so that the warning disappears.

-2
source

Source: https://habr.com/ru/post/1232402/


All Articles