2

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)

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

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.

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

CuriousMind
  • 33,537
  • 28
  • 98
  • 137

2 Answers2

5

If you want to connect via TCP instead of the Unix socket, try changing the host from localhost, to 127.0.0.1.

define('DB_HOST', '127.0.0.1');  // forces TCP
drew010
  • 68,777
  • 11
  • 134
  • 162
  • Tried But that too generates an error: `Warning: mysql_connect(): Can't connect to MySQL server on '127.0.0.1' (111) in /home/gaurish/Dropbox/code/projects/blog/wp-includes/wp-db.php on line 1038` Any more ideas? – CuriousMind Jul 31 '12 at 15:34
  • 1
    Error 111 means access denied, did you add a user that is allowed to connect via TCP? – drew010 Jul 31 '12 at 15:47
  • See http://stackoverflow.com/questions/1420839/cant-connect-to-mysql-server-error-111 – drew010 Jul 31 '12 at 15:49
  • I was able to to figure it out, thanks for suggesting `127.0.0.1` instead of localhost – CuriousMind Jul 31 '12 at 16:22
3

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

the database connection was successful :)

CuriousMind
  • 33,537
  • 28
  • 98
  • 137