强制wordpress通过TCP连接到数据库 [英] Force wordpress to connect to database over TCP

查看:123
本文介绍了强制wordpress通过TCP连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将机器上运行的wordpress连接到在我的机器(本地主机)上通过隧道传输的远程mysql数据库.通过为mysql CLI客户端

I am trying to connect wordpress running on my machine to a remote mysql database which is tunneled on my machine(localhost). The database connection works by giving following parameters to mysql CLI client

$ 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)

在wordpress的wp-config.php文件中,我尝试了以下值:

In wp-config.php file of wordpress, I have tried the following values:

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

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

this doesn't work & throws the following error:

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套接字进行连接时连接失败的原因.

the last line in the above error(Can't connect to local MySQL server through socket) is gives it away why the connection fails as wordpress is trying to connect through an unix socket.

现在,我需要设置哪些参数才能使wordpress作为mysql CLI客户端连接到数据库?

Now, what parameters I need to set to be able to get wordpress to connect to database way as mysql CLI client?

推荐答案

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

i was able to connect using the following settings in 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);

数据库连接成功:)

这篇关于强制wordpress通过TCP连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆