簡體   English   中英

如何在WordPress中建立MySQL數據庫連接?

[英]How to establish a MySQL database connection in WordPress?

我正在嘗試按照教程在Ubuntu 14.04上設置WordPress。 編輯wp-config.php ,遇到"Error establishing a database connection"錯誤"Error establishing a database connection"錯誤。

define('DB_NAME', 'wordpress');

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('WP_ALLOW_REPAIR', true);

DB_NAMEDB_USERDB_PASSWORD的值正確。 我不確定DB_HOST ; 我試過了 :

define('DB_HOST', 'localhost:3306');
define('DB_HOST', '127.0.1.1');
define('DB_HOST', '127.0.1.1:3306');
define('DB_HOST', '159.203.70.104');
define('DB_HOST', '159.203.70.104:3306');

但是沒有人解決這個問題。 MySQL和Apache日志未顯示任何有關該錯誤的信息。 MySQL Shell輸出:

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6291
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

mysql> select User,Host from mysql.user;
+------------------+-----------------------------------+
| User             | Host                              |
+------------------+-----------------------------------+
| root             | 127.0.0.1                         |
| root             | ::1                               |
| debian-sys-maint | localhost                         |
| root             | localhost                         |
| wordpressuser    | localhost                         |
| root             | npvr-vivek-2016-10-17-4gb-nyc3-01 |
+------------------+-----------------------------------+
6 rows in set (0.00 sec)

重新啟動MySQL沒有幫助。 wordpressuser Shell輸出:

mysql -u wordpressuser -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6646
Server version: 5.5.55-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wordpress          |
+--------------------+
2 rows in set (0.00 sec)

您應該可以通過以下方式進行修復:

創建一個新用戶:

CREATE USER 'wordpressuser'@'127.0.0.1' IDENTIFIED BY 'password';

(將“密碼”更改為您的密碼)

在wordpress db上授予此用戶權限:

GRANT ALL PRIVILEGES ON wordpress . * TO 'newuser'@'127.0.0.1';

最后,通過編輯配置文件將127.0.0.1用作數據庫主機:

define('DB_HOST', '127.0.1.1');

如果用戶沒有身份驗證就不能使用127.0.0.1作為數據庫主機

暫無
暫無

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

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