简体   繁体   English

WordPress 建立数据库连接时出错

[英]WordPress Error establishing a database connection

I am new to WordPress, and I am trying to setup it at my local machine.我是 WordPress 的新手,我正在尝试在我的本地机器上设置它。

I am getting error like "Error establishing a database connection".我收到类似“建立数据库连接时出错”的错误消息。

I tried all solutions from WP blogs,我尝试了 WP 博客中的所有解决方案,

    1. created new user with all privileges创建了具有所有权限的新用户
    1. tired with root user.厌倦了root用户。
    1. created and deleted the target database multiple times.多次创建和删除目标数据库。

Nothing is working.没有任何工作。

Does anyone know anything else I can try?有谁知道我还可以尝试什么?

Error establishing a database connection doesn't get any simpler than that. Error establishing a database connection没有比这更简单的了。 Your password, database name, user name, or host is wrong.您的密码、数据库名称、用户名或主机错误。 See http://codex.wordpress.org/Common_WordPress_Errors#Error_Establishing_Database_Connectionhttp://codex.wordpress.org/Common_WordPress_Errors#Error_Establishing_Database_Connection

Are you sure about using localhost as the server?您确定要使用localhost作为服务器吗? Are you using MAMP or WAMP?您使用的是 MAMP 还是 WAMP?

Try using Adminer http://www.adminer.org/ on your PC/Mac to find the database name, etc., and to admin the database when needed.尝试在您的 PC/Mac 上使用 Adminer http://www.adminer.org/查找数据库名称等,并在需要时管理数据库。

If you know can use a shell, try logging into the MySQL server and trying如果您知道可以使用 shell,请尝试登录 MySQL 服务器并尝试

mysql> show databases;

to list all databases to check your database name.列出所有数据库以检查您的数据库名称。

And try并尝试

mysql> mysqlserverinfo --server=root:pass@localhost -d --format=vertical

to get port info, etc. See http://dev.mysql.com/doc/mysql-utilities/1.6/en/mysqlserverinfo.html获取端口信息等。请参阅http://dev.mysql.com/doc/mysql-utilities/1.6/en/mysqlserverinfo.html

I used MAMP for the MySQL server, and used its phpMyAdmin interface to create the database for WordPress and specify its user and password.我将 MAMP 用于 MySQL 服务器,并使用其 phpMyAdmin 界面为 WordPress 创建数据库并指定其用户和密码。

Host, for the new database, was "%" on the "User" tab of phpMyAdmin, which it said was supposed to allow any value, and did let me get a certain way through the process.对于新数据库,主机是 phpMyAdmin 的“用户”选项卡上的“%”,它说它应该允许任何值,并且确实让我通过该过程获得了某种方式。 But, I ended up going into "Login Information" under the "User" tab in phpMyAdmin, and changing "%" to "localhost".但是,我最终进入了 phpMyAdmin 中“用户”选项卡下的“登录信息”,并将“%”更改为“本地主机”。

That allowed me to finish setting up WordPress.这让我完成了 WordPress 的设置。

For future readers, if you are on OSX Yosemite (possibly other versions of OSX as well) and get "Error establishing a database connection" with a local WordPress installation, you may need to do the following:对于未来的读者,如果您使用的是 OSX Yosemite(可能还有其他版本的 OSX)并且在本地 WordPress 安装中出现“建立数据库连接时出错”,您可能需要执行以下操作:

sudo mkdir /var/mysql
sudo chmod 755 /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Yosemite looks in the wrong location for the mysql.sock file, so creating this symlink to the correct location solves the problem. Yosemite 查找 mysql.sock 文件的位置错误,因此创建指向正确位置的符号链接可以解决问题。

The reason the missing symlink is a problem for WordPress specifically is because in your wp-config.php file, define('DB_HOST', 'localhost');缺少符号链接对于 WordPress 来说是一个问题的原因是因为在您的 wp-config.php 文件中, define('DB_HOST', 'localhost'); will not work.不管用。 An alternative workaround is to change this value in your wp-config file to define('DB_HOST', '127.0.0.1');另一种解决方法是在 wp-config 文件中将此值更改为define('DB_HOST', '127.0.0.1'); . .

The OP didn't say what details they changed in their wp-config file to solve the problem (perhaps it was this DB_HOST parameter) so I just thought I'd post this since I wasted a lot of time trying to figure it out! OP 没有说明他们在 wp-config 文件中更改了哪些细节来解决问题(可能是这个 DB_HOST 参数)所以我只是想我会发布这个,因为我浪费了很多时间试图弄清楚!

I tried all these suggestions and still couldn't get it to work.我尝试了所有这些建议,但仍然无法让它发挥作用。 However, I had installed MySQL v8.0.12 and noticed that in the 'Users and Privileges' section, under the user I had set up, the 'Authentication Type' for the password was set to some kind of 'sha2' setting.但是,我安装了 MySQL v8.0.12 并注意到在“用户和权限”部分中,在我设置的用户下,密码的“身份验证类型”设置为某种“sha2”设置。

After trying 100 different things, I eventually fixed this by uninstalling then re-installing MySQL, and during the re-installation, specifically choosing the option button that refers to maintaining compatibility with previous versions of MySQL.在尝试了 100 种不同的事情之后,我最终通过卸载然后重新安装 MySQL 来解决这个问题,并且在重新安装期间,特别选择了指保持与以前版本的 MySQL 兼容的选项按钮。

I think this resulted in my passwords not being automatically hashed, which enabled Wordpress to successfully connect to my MySQL database.我认为这导致我的密码没有被自动散列,这使 Wordpress 能够成功连接到我的 MySQL 数据库。

What worked for me:什么对我有用:
-I moved the wp-config.php file into another folder -我将 wp-config.php 文件移动到另一个文件夹中
-Refreshed the browser and Wordpress will try to re-install - 刷新浏览器,Wordpress 将尝试重新安装
-choose a language - 选择语言
-A message should say Wordpress is already installed and will take you to the database setup page. - 一条消息应该说 Wordpress 已经安装,并将带你到数据库设置页面。
-Enter the same db name, username, password, and host (usually localhost). - 输入相同的数据库名称、用户名、密码和主机(通常是本地主机)。
-Got to www.yoursite.com/admin and you should be able to log in. - 访问 www.yoursite.com/admin,您应该能够登录。

I had this issue and I have searched a lot but no one mentioned a fix like mine!我遇到了这个问题,我已经搜索了很多,但没有人提到像我这样的修复程序! I checked my disk size and I found that my disk size was 100% used.我检查了磁盘大小,发现磁盘大小已 100% 使用。 I tried to clean up some of the files but still there were very large files taking up a lot of space.我试图清理一些文件,但仍然有非常大的文件占用了大量空间。 I kept looking and found that the mysql ./data folder occupied 90% of my disk space.我一直在找,发现mysql ./data文件夹占用了我90%的磁盘空间。 It was the binlog files!这是binlog文件! Very large files I ended up cleaning them up using the Reset Master method.非常大的文件我最终使用重置主方法清理它们。 There is another method PURGE BINARY LOGS which didn't work for me.还有另一种方法PURGE BINARY LOGS对我不起作用。 I had to use Reset Master.我不得不使用重置大师。 Just follow the steps and make sure you have a good backup.只需按照步骤操作并确保您有一个良好的备份。 Good Luck.祝你好运。

Try this before anything!在任何事情之前尝试这个! It fixed my issue.它解决了我的问题。

sudo service mysql restart

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

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