Establishing a remote database connection for local WordPress development

Note: These instructions will actually work for most MySql connection, not just WordPress.

When you are developing a WordPress theme, it’s best to work on it offline. Many times you do not want to have to download the entire MySQL database and set it up in Mamp. When that’s the case, you can download the site files and connect to the WordPress database remotely. Establishing the remote connection is easy just follow these steps.

Establishing a Remote Database connection for local WordPress development

mysql> GRANT ALL ON databasename.* TO databasename@


I’m running an Ubuntu 12. with Nginx

First you need to edit your my.cnf file. Go to etc/mysql/my.cnf and look for the

bind address

comment out the line so it looks like this

#bind adress

$ sudo service mysql restart

go to your mysql database
$ mysql -u [user] -p

After that add a user to access your database such as:

mysql> GRANT ALL ON database_name.* TO IDENTIFIED BY ‘your_password’;

Replace xx.xx.xx.xx with your local IP address of your laptop/desktop
or if it is dynamic you can add them either by: ‘191.151.0.%’ as a dynamic C-class. (this is less secure, but will allow you to connect from more locations)
mysql> exit
$ sudo service mysql restart
You might also have to whitelist your computers IP Address on your server depending on your security. If you have IP Tables and Firewalls, you are going to have

Next Steps:
From here the operations will vary based on your server and local environments.
Change the bind address to the ip address of your database server. If your webserver and database server are the same, this should still work.

From etc/mysql/my.cnf, look for the port number for mysql. Then double check what port is running on the database server by running the following command in terminal.

$ netstat -plutn

MySQL should be listening on

Back in your local install, open up your wp-config.php file and add you remote database ip address and port to the DB_HOST directive.
/** MySQL hostname */
define(‘DB_HOST’, ‘’);

That should do the trick!

If you are looking for a professional WordPress Developer in New York City contact DigiMix Web Design NYC. We’re expert WordPress developers, web designers and digital strategist helping our clients achieve success online.