WordPress database connection error after server migration

Having trouble with WordPress database connectivity after moving to new server

I’m facing a database connection issue with my WordPress site. When I try to access the site, I keep getting the database connection error message.

What I did:
I had a working WordPress installation on one server. I created a backup of the AWS disk that contained all the configuration files and used it to set up a new server instance.

Steps I already tried:

  • Verified all configuration settings look correct
  • Added the new server IP address to MySQL with proper credentials
  • Used debug output to confirm all database parameters are showing up correctly
  • Replaced the config file with a fresh copy from the original working server
  • Double checked file permissions are set properly

Everything seems to be configured the same way as the working server but I still can’t establish the database connection. What else should I check to resolve this issue?

hmm, did u check your firewall settings? might be blocking the db connection. also, try pinging the db from the new server, helps to see if they can talk to each other. good luck!

Had the same issue last month during a client migration. Turned out to be the database host config in wp-config.php. Double-check your DB_HOST value - it needs to point to the right endpoint for your new environment. Sometimes localhost works fine on one server but needs the actual IP or hostname on another. Also make sure your new server has the PHP MySQL extensions installed and running. Try running a quick PHP script with mysql_connect or mysqli_connect outside WordPress to test the raw database connection. That’ll tell you if it’s a WordPress problem or just server connectivity issues.

Check if MySQL is actually running on your new server. I hit this exact issue during a client migration and wasted hours on config files before realizing MySQL wasn’t even started. Run systemctl status mysql or service mysql status to check. Also caught me off guard - the bind-address in my.cnf was set to 127.0.0.1, blocking external connections even with correct user permissions. Try connecting with the command line mysql client using the same credentials WordPress uses. If that fails, you’ve got a server-level database issue, not a WordPress problem.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.