Setting an external database for WordPress from wp_config file

Problem:

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

Read More

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/

Related posts

Leave a Reply

1 comment

  1. 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