【问题标题】:MySQL Wordpress Nginx dnsmasq: Error: Error establishing a database connectionMySQL Wordpress Nginx dnsmasq:错误:建立数据库连接时出错
【发布时间】:2020-01-04 14:14:27
【问题描述】:

我正在尝试设置本地开发环境。我无法让 wordpress 连接到 mysql。我可以使用以下命令复制错误:

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

结果:

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.

我尝试过的事情:

  • 查看 wp-config 并确保数据库名称和凭据正确。我可以通过 cli 连接
  • 更新了 homebrew.mxcl.mysql.plist 以包括 --bind-address=*
  • 查看了mysql的socket位置:mysql_config --socketproducef/tmp/mysql.sock
  • 更新了 php.ini 以反映下面的附件
  • 更新了 my.cnf 以反映 bind-address = *
  • 我使用的是dnsmasq(如https://medium.com/@charlesthk/wordpress-on-os-x-with-nginx-php-mysql-62767a62efc4所示)

环境

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

【问题讨论】:

    标签: php mysql wordpress nginx


    【解决方案1】:

    我想通了。问题是客户端未知的caching_sha2_password 身份验证方法。为了解决这个问题,我跑了:

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

    我通过以下方式找到了这个:创建一个基本的测试脚本:

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

    并且产生的错误提到了caching_sha2_password认证方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-24
      • 2021-04-19
      • 2021-05-28
      • 1970-01-01
      • 2015-08-11
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多