2
votes

Problem:

How to use an external database, that is not located in localhost, by setting the WordPress configuration in the file wp_config.

So, all WordPress files (wp_content, wp_admin, ...) are in Local computer A, and the database is in Server B.

Can this be done ?, how would the settings be ?

What I have tried:

define('DB_HOST', 'example');
define('DB_HOST', 'example.com');
define('DB_HOST', 'http://example.com');
define('DB_HOST', 'example.com:22');

Notes:

  • The server is using MySQL on Linux.
  • When I change the configuration, to use a local database, it works perfect. So it is not WordPress, is the connection setting.
  • username, password, and database name (DB_NAME, DB_USER, DB_PASSWORD) are correct.

Current error:

Error establishing a database connection

Related links:

http://codex.wordpress.org/Editing_wp-config.php

http://wordpress.org/support/topic/connect-local-wordpress-site-to-remote-database

http://digwp.com/2010/08/pimp-your-wp-config-php/

1
Does the database user that you are using have permission to connect remotely? See this thread and this Stack Overflow question. - vvanasten
@wanasten sounds good, my first guess is that root has remote permissions, but I'm gonna check it, do you know how to check that ? - Francisco Corrales Morales
root probably doesn't have them by default. If you're using phpMyAdmin: log in and click the Users tab, the allowed hosts will be displayed in the Hosts column. - vvanasten

1 Answers

0
votes

To start the diagnosis, I would do the following :

  • Try to connect to the DB with the user you have from another device. If you can, we are able to rule out the connectivity problem / remote access right on the DB side. Be sure to allow the mySql listening port through any firewall you may have
  • define('DB_HOST', 'example.com:port'); is the correct format. Can you try to use the IP address? Also mySql listen on port 3306 by default.
  • Quite unlikely but also check the outbound connection from your WP host to the DB server / mySql port