简体   繁体   中英

MySQL Wordpress Nginx dnsmasq: Error: Error establishing a database connection

I'm trying to get a local development environment set up. I can't get wordpress to connect to mysql. I can duplicate the error with the following command:

wp core install --url=http://uganda.localhost/ --title="Uganda Aid" --admin_user="Jack" --admin_password="thepassword" --admin_email="JackWinterstein@msf.org"

Result:

Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localhost`. This could mean your host’s database server is down.

Things I tried:

  • Looked in wp-config and made sure the database name and credentials were correct. I can connect via cli
  • Updated homebrew.mxcl.mysql.plist to include --bind-address=*
  • Looked at the mysql socket location: mysql_config --socket producef /tmp/mysql.sock
  • Updated php.ini to reflect the attached below
  • Updated my.cnf to reflect bind-address = *
  • I am using dnsmasq (as shown in https://medium.com/@charlesthk/wordpress-on-os-x-with-nginx-php-mysql-62767a62efc4 )

Environment

Darwin osx10.14, mysql Ver 8.0.17, nginx version: nginx/1.17.3, Wordpress 5.2.2, PHP 7.3.9

I figured it out. The problem was that caching_sha2_password authentication method unknown to the client. To fix this I ran:

ALTER USER jack@localhost IDENTIFIED WITH mysql_native_password BY 'thepassword';

I found this by: creating a basic test script:

<?php
$link = mysqli_connect('localhost', 'jack', 'thepassword');
if (!$link) {
    die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

And the resulting error mentioned the caching_sha2_password authentication method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM