简体   繁体   English

Wordpress 无法连接到 mysql 服务器

[英]Wordpress cannot connect to mysql server

I have run a mysql server in my macbook, where I can access via both mysql command mysql -u root and navicat application.我在我的 macbook 中运行了一个 mysql 服务器,我可以通过 mysql 命令mysql -u root和 navicat 应用程序访问。 However, when I open the install page of a brand new wordpress app in my macbook.但是,当我在我的 macbook 中打开一个全新的 wordpress 应用程序的安装页面时。 During the installation, I had got:在安装过程中,我得到了:

MySQL 错误的图像

MySQL 8.x actually IS supported, but requires a slightly different command when creating the user and password, as version 8 expects passwords to be SHA256 encoded. MySQL 8.x 实际上是支持的,但在创建用户和密码时需要一个稍微不同的命令,因为版本 8 期望密码是 SHA256 编码的。

When creating the database user, with the MySQL prompt, use the following:创建数据库用户时,在 MySQL 提示下,使用以下命令:

ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

So WITH mysql_native_password being the main difference.所以WITH mysql_native_password是主要区别。 Good luck!祝你好运!

Use 127.0.0.1 rather than localhost使用 127.0.0.1 而不是 localhost

I came across this when installing WordPress locally for plugin development/unit testing and deciding to use the latest of everything!我在本地安装 WordPress 进行插件开发/单元测试并决定使用最新的一切时遇到了这个问题! ie MySQL 8.0.11, PHP 7.1.16, WordPress 4.9.7.即 MySQL 8.0.11、PHP 7.1.16、WordPress 4.9.7。

I was able to connect to the database with Sequel Pro desktop client but WordPress would not connect.我能够使用Sequel Pro桌面客户端连接到数据库,但 WordPress 无法连接。

Migrating to MySQL 8.0 for Wordpress – episode 1 came across a similar problem where I was reminded to add define('WP_DEBUG', true); 为 Wordpress 迁移到 MySQL 8.0 – 第 1 集遇到了类似的问题,我被提醒添加了define('WP_DEBUG', true); to my wp-config.php :到我的wp-config.php

Then, the output above was prepended with:然后,上面的输出前面加上:

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/BrianHenryIE/Sites/wptest/wp-includes/wp-db.php on line 1531

Line 1531 doesn't really tell much, just the error is sometimes surpressed:第 1531 行并没有真正说明什么,只是有时会抑制错误:

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 );
}

Another SO answer, mysqli_real_connect(): (HY000/2002): No such file or directory , told me to use 127.0.0.1 instead of localhost , which I changed in my wp-config.php , define( 'DB_HOST', '127.0.0.1' );另一个 SO 答案, mysqli_real_connect(): (HY000/2002): No such file or directory ,告诉我使用127.0.0.1而不是localhost ,我在wp-config.php更改了它, define( 'DB_HOST', '127.0.0.1' ); , and everything worked! ,一切正常!

It turned out to be I have MySQL version at 8.0.11 that might be unsupported by WordPress (I guess).结果是我的 MySQL 版本为 8.0.11,可能不受 WordPress 支持(我猜)。 When I switch the mysql version from 8.0.11 to 5.7.16.当我将 mysql 版本从 8.0.11 切换到 5.7.16 时。 It works.有用。 Fairly wired though.虽然相当有线。

For my case the issue was MySQL 8.0.18 is setup to run on port 3308 for WAMPserver 3.2.0就我而言,问题是 MySQL 8.0.18 设置为在 WAMPserver 3.2.0 的端口 3308 上运行

Define non standard port in wp-config.php在 wp-config.php 中定义非标准端口

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

Do not connect with MySQL root user.不要连接 MySQL root 用户。 Create another user in MySQL to connect in Wordpress.在 MySQL 中创建另一个用户以在 Wordpress 中连接。

尝试这个:

setsebool -P httpd_can_network_connect=1

What I did that solved my issue was to update to PHP 7.2.x on my IIS Server, then assigned this version to the Wordpress Website in PHPManager (In IIS Manager).我所做的解决我的问题是在我的 IIS 服务器上更新到 PHP 7.2.x,然后将此版本分配给 PHPManager 中的 Wordpress 网站(在 IIS 管理器中)。

This worked for me.这对我有用。

In MySQL 8 the team changed default value of default_authentication_plugin configuration variable from previous mysql_native_password to caching_sha2_password .在 MySQL 8 中,团队将 default_authentication_plugin 配置变量的默认值从以前的mysql_native_passwordcaching_sha2_password

What this means is that when a client connects to MySQL without specifying which password encryption method it uses MySQL assumes it to be using caching_sha2_password .这意味着当客户端连接到 MySQL 时没有指定它使用的密码加密方法,MySQL 假定它使用caching_sha2_password But most of clients currently in use are assuming to use mysql_native_password .但是目前使用的大多数客户端都假设使用mysql_native_password

To fix this problem, edit your mysql config file.要解决此问题,请编辑您的 mysql 配置文件。 On linux it should be at:在 linux 上它应该在:

/etc/my.cnf

Find and uncomment the following line:找到并取消注释以下行:

default_authentication_plugin=mysql_native_password

if you can't find it, just add it under [mysqld] .如果找不到,只需将其添加到[mysqld]

You must restart mysql after this change.在此更改后,您必须重新启动 mysql。 On CentOS 7 you can issue this command:在 CentOS 7 上,您可以发出以下命令:

systemctl restart mysqld

This permanent solution will fix mysql connection error for all wordpress installations.此永久解决方案将修复所有 wordpress 安装的 mysql 连接错误。

对于 docker mysql 实例

docker run --name eight-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --default-authentication-plugin=mysql_native_password

I had this issue too - problem was with the MySQL database.我也有这个问题 - 问题出在 MySQL 数据库上。 Changed database to utf8_general_ci and connection worked fine将数据库更改为utf8_general_ci并且连接工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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