簡體   English   中英

如何調試與WordPress建立數據庫連接的錯誤

[英]How to debug error establishing a database connection with WordPress

當我嘗試以localhost訪問我的WordPress網站時,我得到:

建立數據庫連接時出錯。

我該如何調試這個問題? 我能看到哪些日志?

我可以使用localhost上的用戶wordpressuser登錄MySQL。 我似乎對wordpressuser在數據庫wordpress上有正確的授權:

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 ,該站點現在加載在localhost上。 很明顯, wp-config.php定義的值與實際傳遞給new wpdb(...)的值之間存在不匹配,盡管我還沒有能夠進一步跟蹤它。

與其中一條評論中的建議不同:

  1. 這不是Web服務器的問題。 該網站現在正常工作,從localhost或外部。

  2. 命令wget localhost現在可以正常工作。 它下載了一個包含wordpress設置頁面的index.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM