1
votes

I try to configure Wordpress on my Mac. I use an Apache server with MySQL, installed via MacPorts.

So, from phpMyAdmin, I created a "hellowp" user with a "hellowp" database. I can correctly log in with this user, and I have access to the hellowp database.

But when I set these parameters in my wp-config.php, or from the Wordpress configuration GUI, Wordpress can't login to database.

I enabled the debug, and this is the errors I get:

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/var/www/hellowp/wp-includes/wp-db.php on line 1342

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /private/var/www/hellowp/wp-includes/wp-db.php on line 1372

Warning: mysql_connect(): No such file or directory in /private/var/www/hellowp/wp-includes/wp-db.php on line 1372

My PHP version is 5.5.10. I use this server for many projects, as some running on Drupal, and I do not have any problem with them.

I also tried to log as MySQL root user in Wordpress, but the error still the same.

EDIT 1 : I tried to log into my server from MySQL Workbench and SURPRISE, the server cannot be found at 127.0.0.1... What's strange is that phpMyAdmin still working, and other projects and Drupal use the database without any problem. I will investigate about that, maybe a firewall issue. Will update when I've got news.

EDIT 2: Ok, so I checked what many of you were telling, and yes many of you were right : MySQL connection from PHP is working only when using PDO (what I do in all of my projects and that Drupal do). mysql_connect and mysqli_connect are triggering an error. But the fact is that I will not rewrite Wordpress, and I'm using the latest version. So I will try to find a solution to make mysql_connect and mysqli_connect work on my PHP configuration.

**EDIT 3: THE SOLUTION: ** I installed Percona server (a MySQL fork) few months ago, to replace mysql server. And during this install, in my php.ini, I setted the socket only for PDO, and not for mysqli and mysql. So, I had to set the socket for all mysql extensions in my php.ini. This is those lines:

pdo_mysql.default_socket="/opt/local/var/run/percona/mysqld.sock"
mysql.default_socket = "/opt/local/var/run/percona/mysqld.sock"
mysqli.default_socket = "/opt/local/var/run/percona/mysqld.sock"
2
The solution is in the error message; it's deprecated/deleted. Use mysqli_connect() Plus, you can't mix those two APIsFunk Forty Niner
It gives you the cause in those error messages.Brandon White
@Fred-ii-, that's wrong. mysql_connect is deprecated in 5.5 but not deleted. @maxime, please, check /private/var/www/hellowp/wp-includes/wp-db.php path. Error is No such file or directory.Naeel Maqsudov
You could very well be right. I have however seen a few cases where the server an OP was on, the mysql_* functions were indeed deleted. @NaeelMaqsudov So, I'm 50% right on this one ;-)Funk Forty Niner
Here are the lines 1371 to 1375 of wp-db.php. I do not see any include or file: if ( WP_DEBUG ) { $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } else { $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); }maxime

2 Answers

2
votes

The first error message tells you that Wordpress cannot find your database, most likely your hostname is incorrect - its normally 'localhost' but you could try 127.0.0.1 which I believe better for Macs.

The remaining error messages are misleading - If wordpress fails to make a Mysqli connection, it will try the deprecated mysql, and in your case, will also fail because it cannot find the database.

1
votes

Not sure but this is how Id usually debug it.

  1. Login to the db via command line. This ensures its in your path and everything is working correctly.
  2. If that works, here is a section from my local dev environment.

    // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'foo');

    /** MySQL database username */ define('DB_USER', 'foo');

    /** MySQL database password */ define('DB_PASSWORD', 'foooo');

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