2014-06-08 35 views
3

數據庫連接,當我嘗試訪問我的WordPress網站爲localhost,我得到:如何調試錯誤建立與WordPress

錯誤建立一個數據庫connection`。

如何調試此問題?我能看到日誌在哪裏?

我可以在localhost上用戶wordpressuser登錄MySQL。我似乎對數據庫wordpresswordpressuser正確補助:

[email protected]# 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 [email protected]; 
+----------------------------------------------------------------------------------------------------------------------+ 
| Grants for [email protected]                     | 
+----------------------------------------------------------------------------------------------------------------------+ 
| 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,我得到:

[email protected]# mysqlaccess localhost wordpressuser wordpress -pmypassword 
mysqlaccess Version 2.06, 20 Dec 2000 
By RUG-AIV, by Yves Carlier ([email protected]) 
Changes by Steve Harvey ([email protected]) 
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失敗,連接被拒絕:

[email protected]:~$ 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)。

如何調試此問題?

+1

[wordpress]標籤很好,因爲OP在WordPress安裝中顯然遇到了他們的問題。這可能不是一個WordPress特定的問題,但是對於我們所知的所有*它都可能是由WordPress本身引起的。 – BoltClock

回答

0

我設法如下,以 「修復」 的問題:

試圖找到其中的PHP訪問MySQL數據庫的地方,我做了AA

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_PASSWORD,DB_NAME,DB_HOST,由於某種原因,網站現在確實在localhost上加載。顯然,在wp-config.php中定義的值與實際傳遞給 new wpdb(...)的值之間存在一些不匹配。我可以發誓,wp-config.php的值是正確的,我三次檢查他們幾次。一旦我完全不瞭解php,我會嘗試進一步調試問題。現在,我將依靠硬編碼的值(幸運的是,硬編碼的變量幾乎不會在其他任何地方使用),

與對我的問題發表評論的人相反:

  1. 這與我的網絡服務器無關。該網站現在正常工作,從本地主機和外部。

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