Troubleshooting ‘Error establishing a database connection’ in WordPress

Solution:
In your cPanel, verify your database credentials:

Hostname

Database Name

Username

Password

Make sure all of these are correct for your new server. On shared hosting, the database username often changes, so double-check it carefully.