Migrating MySQL DB's/Users to a new Private DB server

June 20, 2018 190 views
MySQL Firewall LEMP Let's Encrypt Ubuntu 18.04

Hi all,

I successfully deployed a LEMP stack to host multiple Wordpress sites on an Ubuntu 18.04 server droplet. I had multiple domains hosted and working successfully with UFW setup as the Firewall. The two Wordpress sites worked/still worked perfectly.

I then setup a separate droplet running just MySQL server and again UFW as the Firewall but more restrictive. I allowed access to the LEMP private IP address and set the bind-address in MySQL to the DB servers private IP. All this was done using the following tutorials:

How To Set Up a Remote Database to Optimize Site Performance with MySQL on Ubuntu 16.04

and

How To Migrate a MySQL Database To A New Server On Ubuntu 14.04

The latter used to migrate the DB's and users. I also ensure the users @localhost had the necessary permissions and added the same user with the same permissions but @lempserverip as directed. However, no matter what I try, I keep getting

Error establishing a database connection

If I try to access the wp-admin page on the site I get a different message that shows:

Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at DATABASE_SERVER_IP. This could mean your host’s database server is down.

Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

I have tried everything and scoured Digital Ocean and Google but to no avail.

Here are the last few lines of the MySQL error log:

2018-06-20T18:19:37.608210Z 0 [Note] Server hostname (bind-address): 'DB_SERVER_IP'; port: 3306
2018-06-20T18:19:37.608224Z 0 [Note]   - 'DB_SERVER_IP' resolves to 'DB_SERVER_IP';
2018-06-20T18:19:37.608270Z 0 [Note] Server socket created on IP: 'DB_SERVER_IP'.
2018-06-20T18:19:37.616696Z 0 [Note] Event Scheduler: Loaded 0 events
2018-06-20T18:19:37.616954Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.22-0ubuntu18.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
2018-06-20T18:20:19.566404Z 2 [Warning] IP address 'LEMP_SERVER_IP' could not be resolved: Name or service not known
2018-06-20T18:20:19.566838Z 2 [Note] Access denied for user 'root'@'LEMP_SERVER_IP' (using password: YES)
2018-06-20T18:20:26.897598Z 3 [Note] Access denied for user 'root'@'LEMP_SERVER_IP' (using password: YES)
2018-06-20T18:20:32.879002Z 4 [Note] Access denied for user 'root'@'LEMP_SERVER_IP' (using password: YES)
2018-06-20T18:20:34.187551Z 5 [Note] Access denied for user 'root'@'LEMP_SERVER_IP' (using password: YES)
2018-06-20T18:20:35.193464Z 6 [Note] Access denied for user 'root'@'LEMP_SERVER_IP' (using password: YES)

Any help or advice?

Thanks,

1 Answer

MySQL is treaing 'root'@'LEMPSERVERIP' as a different user than 'root'@'localhost'. You need to create the 'root'@'LEMPSERVERIP' user, set its password and grant it the priveleges you want.

Something like:
CREATE USER 'root'@'LEMPSERVERIP' IDENTIFIED BY 'yourNewPassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'LEMPSERVERIP';
FLUSH PRIVILEGES;

Have another answer? Share your knowledge.