力WordPress的通过TCP连接到数据库(Force wordpress to connect

2019-09-20 12:49发布

我想我的机器上连接的WordPress运行到这是我的机器(本地主机)上隧道远程MySQL数据库。 数据库连接可以通过给以下参数mysql命令行客户端

$ mysql --protocol=TCP -P 10000 -h localhost -u username -p'password' db_name

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 93438893
Server version: 5.5.8-log Source distribution

Copyright (c) 2000, 2011, 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                |
| db_name                           |
+-----------------------------------+
2 rows in set (1.38 sec)

wp-config.php的WordPress的文件,我已经尝试了以下值:

define('DB_NAME', 'db_name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
define('DB_PORT', 10000);

这不起作用&引发以下错误:

Warning: include(/home/gaurish/Dropbox/code/projects/blog/wp-content/advanced-cache.php): failed to open stream: No such file or directory in /home/gaurish/Dropbox/code/projects/blog/wp-settings.php on line 62 
Warning: include(): Failed opening '/home/gaurish/Dropbox/code/projects/blog/wp-content/advanced-cache.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/gaurish/Dropbox/code/projects/blog/wp-settings.php on line 62 
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/gaurish/Dropbox/code/projects/blog/wp-includes/wp-db.php on line 1038

上述错误的最后一行( Can't connect to local MySQL server through socket为什么连接失败,因为WordPress是试图通过一个Unix套接字连接)是给它了。

现在,我需要什么参数设定为能够获得的WordPress连接到数据库的方式mysql CLI客户端?

Answer 1:

如果您想通过TCP而不是Unix套接字连接,尝试改变从主机localhost ,到127.0.0.1

define('DB_HOST', '127.0.0.1');  // forces TCP


Answer 2:

我能够使用以下设置连接wp-config.php

define('DB_NAME', 'db_name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', '127.0.0.1:10000');
define('DB_PORT', 10000);

数据库连接成功:)



Answer 3:

检查了这一点: http://chxo.com/be2/20040511_5667.html

可以解释这一切非常好(没看到点重新迭代它说什么,这是我去的时候我需要做的话)。



文章来源: Force wordpress to connect to database over TCP