如何解决 Google App Engine 的 WordPress XAMPP 本地主机上的“建立数据库连接时出错”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20213659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:25:39  来源:igfitidea点击:

How to Resolve "Error Establishing a Database Connection" on WordPress XAMPP Localhost for Google App Engine

wordpressgoogle-app-engine

提问by Catalyx

Following Google App Engine's instructionsfor creating a local WordPress development platform, I created the database and initial user using the instruction's MySQL direction:

继谷歌App Engine的指令创建本地WordPress的开发平台,我创建了数据库,并使用该指令的MySQL的方向初始用户:

CREATE DATABASE IF NOT EXISTS wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'wp_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';

After running it without errors reported, MySQL subsequently reported back:

运行后没有报错,MySQL随后返回:

CREATE DATABASE IF NOT EXISTS wordpress_db;# 1 row affected.

CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'wp_password';# MySQL returned an empty result set (i.e. zero rows).

GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';# MySQL returned an empty result set (i.e. zero rows).

While the command line runs dev_appserver.py, I try reaching the WordPress app and get instead:

当命令行运行 dev_appserver.py 时,我尝试访问 WordPress 应用程序并获得:

Error establishing a database connection

建立数据库连接时出错

I've removed and recreated the database (wordpress_db) and user (wp_user) without reaching the WP app.

我已经删除并重新创建了数据库 (wordpress_db) 和用户 (wp_user),而没有访问 WP 应用程序。

Any suggestion how to resolve this is appreciated.

任何解决此问题的建议表示赞赏。

Thanks, this is my App Engine log:

谢谢,这是我的 App Engine 日志:

2013-11-26 17:40:25 Running command: "['C:\Program Files\Python27\python.exe', u'C:\Program Files\Google\google_appengine\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', u'C:\Documents and Settings\User\My Documents\Catalyx\Catalyx-GoogleAppEngine\Catalyx']" 2013-11-26 17:40:26 (Process exited with code -1073741515)

2013-11-26 17:40:25 运行命令:“['C:\Program Files\Python27\python.exe', u'C:\Program Files\Google\google_appengine\dev_appserver.py', '--skip_sdk_update_check =yes', '--port=8080', '--admin_port=8000', u'C:\Documents and Settings\User\My Documents\Catalyx\Catalyx-GoogleAppEngine\Catalyx']" 2013-11-26 17 :40:26(进程退出,代码为 -1073741515)

采纳答案by danmux

As you have mentioned you are following googles own instructions...

正如您所提到的,您正在遵循谷歌自己的说明......

then in the section titled ... Step 4. Create your wp-config.php configuration file

然后在标题为...的部分中。 Step 4. 创建您的 wp-config.php 配置文件

where the instructions state that you should replace the existing lines with the following:

其中说明指出您应该使用以下内容替换现有行:

/** The name of the database for WordPress */
define('DB_NAME', '**wordpress_db**');

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

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

You should enter those lines without the **either side of the words like so...

你应该输入这些行,而**不是像这样...

/** The name of the database for WordPress */
define('DB_NAME', 'wordpress_db');

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

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

When you hit the default root url for your local app - normally localhost:8080you may get some odd redirects, so instead go direct to the local Wordpress install url...

当您点击本地应用程序的默认根 url 时 - 通常localhost:8080您可能会收到一些奇怪的重定向,因此请直接转到本地 Wordpress 安装 url...

http://localhost:8082/wp-admin/install.php

You should then get the nice Wordpress install page that you were expecting

然后你应该得到你期待的漂亮的 Wordpress 安装页面

回答by ken

This happens to me and I have a very 'good' evening with it. So hopefully someone can found this problem earlier...

这发生在我身上,我度过了一个非常“美好”的夜晚。所以希望有人能早点发现这个问题......

I am trying to replicate the server wordpress on localhost. After replacing the actual URL with localhost, thing works perfectly. Except one thing, the newly created page is always in "Error Establishing a Database Connection”.

我正在尝试在本地主机上复制服务器 wordpress。用 localhost 替换实际 URL 后,一切正常。除了一件事,新创建的页面总是在“建立数据库连接时出错”。

Let me put in sequence why this problem happened.

让我按顺序列出为什么会出现这个问题。

  1. on local pc I already have an old wordpress directory wp/
  2. on server my wordpress was placed under wp/
  3. when i copy the package to my local pc, i placed it to wp2/ (remember wp/ already taken?)
  1. 在本地电脑上我已经有一个旧的 wordpress 目录 wp/
  2. 在服务器上,我的 wordpress 被放置在 wp/ 下
  3. 当我将包复制到我的本地电脑时,我把它放到了 wp2/(还记得 wp/ 已经被占用了吗?)

So who's the culprit? it's the .htaccess

那么罪魁祸首是谁?这是 .htaccess

RewriteBase /wp/

So it pointing to another database used by wp, which is of course resulting in error! The fix is easy, just change it to wp2!

所以它指向了wp使用的另一个数据库,这当然导致错误!修复很简单,只需将其更改为 wp2!

RewriteBase /wp2/

Voila! Cheers and the evening suddenly become beautiful again! :)

瞧!干杯,晚上突然又变美了!:)

回答by Abanoub Hanna

To fix this problem try those fixes :

要解决此问题,请尝试以下修复:

  1. Open wp-config.php, check line DB_USER, DB_PASSWORD, DB_HOST, DB_NAME. Make sure the values is same with mysql access.

  2. If you use Dedicated server or VPS hosting, try to restart your mysql server by typing : -service mysql restart or -service mysql start but if you use shared hosting, ignore this step!

  3. if all the previous fixes can not fix it, so it's a server-side problem! it is not your error! so let the hosting company fix this error for you because it is their error! contact them or give them a day or so and they will solve this error and the problem will disappear automatically. you can also check this video for the error establishing database connection fixes

  1. 打开 wp-config.php,检查 DB_USER、DB_PASSWORD、DB_HOST、DB_NAME 行。确保值与 mysql 访问相同。

  2. 如果您使用专用服务器或 VPS 托管,请尝试通过键入:-service mysql restart 或 -service mysql start 重新启动您的 mysql 服务器,但如果您使用共享托管,请忽略此步骤!

  3. 如果之前的所有修复都无法修复,那就是服务器端问题!这不是你的错误!所以让托管公司为您修复这个错误,因为这是他们的错误!联系他们或给他们一天左右的时间,他们将解决此错误,问题将自动消失。您还可以查看此视频以了解建立数据库连接的错误修复