gpt4 book ai didi

php - 如何调试与 WordPress 建立数据库连接的错误

转载 作者:可可西里 更新时间:2023-11-01 07:44:44 24 4
gpt4 key购买 nike

当我尝试以 localhost 身份访问我的 WordPress 网站时,我得到:

Error establishing a database connection`.

我该如何调试这个问题?我可以在哪里查看日志?

我可以在 localhost 上使用用户 wordpressuser 登录 MySQL。我似乎对数据库 wordpress 上的 wordpressuser 有正确的授权:

root@myhost# mysql -hlocalhost -uwordpressuser -pmypassword 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 109
Server version: 5.5.37-0+wheezy1 (Debian)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants for wordpressuser@localhost;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for wordpressuser@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser'@'localhost' IDENTIFIED BY PASSWORD '*somepassword' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpressuser'@'localhost' |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

但是当我运行 mysqlaccess 时,我得到:

root@myhost# mysqlaccess localhost wordpressuser wordpress -pmypassword
mysqlaccess Version 2.06, 20 Dec 2000
By RUG-AIV, by Yves Carlier (Yves.Carlier@rug.ac.be)
Changes by Steve Harvey (sgh@vex.net)
This software comes with ABSOLUTELY NO WARRANTY.
Password for MySQL user wordpressuser:

Sorry,
An error occured when trying to connect to the database
with the grant-tables:
* Maybe YOU do not have READ-access to this database?
* If you used the -U option, you may have supplied an invalid username?
for the superuser?
* If you used the -U option, it may be possible you have to supply
a superuser-password to, with the -P option?
* If you used the -P option, you may have supplied an invalid password?

wget localhost 因连接被拒绝而失败:

user@myhost:~$ wget localhost
--2014-06-08 01:11:29-- http://localhost/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2014-06-08 01:11:29 ERROR 500: Internal Server Error.

我的 wp-config 似乎有正确的凭据(DB_NAME、DB_USER、DB_PASSWORD、DB_HOST)。

我该如何调试这个问题?

最佳答案

我设法临时解决了这个问题,如下所示:

试图找到php访问mysql数据库的地方,我做了一个

grep Ri db.user /var/www

找到那个

/var/www/wp-includes/load.php

在这一行创建数据库:

$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );

我尝试对 DB_USER 的值进行硬编码。 DB_PASSWORDDB_NAMEDB_HOST,该站点现在确实加载到本地主机上。显然,wp-config.php 中定义的值与实际传递给 new wpdb(...) 的值不匹配,尽管我没有目前还无法进一步追踪。

与其中一条评论中的建议不同:

  1. 这不是网络服务器的问题。该站点现在可以在本地主机内或从外部正常运行。

  2. 命令 wget localhost 现在可以正常工作了。它下载一个包含 wordpress 设置页面的 index.html

关于php - 如何调试与 WordPress 建立数据库连接的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24103221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com