Separate database server on private network

May 23, 2016 673 views
MySQL WordPress


I've setup 2 droplets both running Ubuntu 16.04 x64 and enabled private network on both.

I've got my Wordpress files on one droplet and my database on a separate droplet.

I've edited /etc/mysql/mysql.conf.d/mysqld.cnf on the database server and changed the bind-address to be the private IP of the database server.

I've also run 'sudo ufw allow from WEB-SERVER-PRIVATE-IP to any port 3306 proto tcp'. Where WEB-SERVER-PRIVATE-IP is the wordpress files server private IP address.

I've edited the wordpress wp-config file: define('DB_HOST', 'DATABASE-PRIVATE-IP'); Where DATABASE-PRIVATE-IP is my database server private IP address.

I get "Error establishing a database connection"

Where have I gone wrong?


1 Answer


In addition to allowing remote connections through the firewall and network interface, you will also need to add a MySQL user that is allowed to authenticate remotely. By default, most users should be allowed to connect only from localhost.

To do that, run mysql -u root -p and enter your MySQL root password and run the following command to add the user:

GRANT ALL ON database_name.* TO username@xx.xx.xx.xx IDENTIFIED BY 'your_password';

Make sure you replace the red parts with the relevant details, with xx.xx.xx.xx being the private IP of the web server. The username doesn't have to be unique, as long as the host and username combination is unique.

Once you've done that, run


while still in the MySQL prompt in order to have it reload the privileges/credentials table and you should then be able to connect to the database from your web server.

  • Thanks, still not working though :(

    I've tried logging in to the web server to see if the user created above can access the database server by using:

    mysql -u wordpressuser -h database_server_IP -p

    After I enter a password though, nothing happens. So assume there must be a problem there.

    • definitely firewall problem. temporarily disable firewall or run only the following command to test

      sudo ufw allow 3306
      • Huh, nope still not working. Tried disabling the firewall on the web server and the database server.

        # mysql -u wordpressuser -h database_ip -p
        Enter password:
        ERROR 2003 (HY000): Can't connect to MySQL server on 'database_ip' (110)
  • @kamaln7
    thanks for your reply. i have created such remote server using help from few places and i succeed. but still it would be great to see the following tutorial for ubuntu 16.04
    How To Set Up a Remote Database to Optimize Site Performance with MySQL

    there's already an open request for that though.
    Need Remote Database setup tutorial for ubuntu 16.04

    by Justin Ellingwood
    When your site begins to get more visitors, you may have to think about how to handle the additional traffic. One easy way of doing this is to separate your database operations from your web server so that each can handle its own load. In this guide, we'll demonstrate how to do this for a WordPress site built on Nginx by configuring a remote MySQL database.
Have another answer? Share your knowledge.