When it comes to website management, site migrations are often necessary due to hosting changes, scaling up operations, or restructuring the underlying infrastructure. While typically straightforward, problems can arise during or after the process—particularly with databases. In this article, we explore the case of recurring database connection errors after a migration on Bluehost, and how carefully inspecting and repairing MySQL user privileges ultimately restored full database access.
TLDR:
Following a website migration on Bluehost, recurring database connection errors disrupted service. The root cause stemmed from MySQL user privileges not transferring properly during the migration process. A methodical examination of user roles and systematic privilege reassignment resolved the issue completely. This situation underscores the importance of verifying database permissions post-migration.
The Fallout After Website Migration
Website owners expect a seamless transition when migrating from one server environment to another. However, shortly after migrating several WordPress websites to Bluehost’s shared hosting environment, users began encountering the following error:
Error establishing a database connection
This error is often synonymous with incorrect database credentials in the wp-config.php file. However, after verifying that the database name, username, password, and host were all correct, it became evident that the issue was more complex than an input mistake.
Evaluating the Common Causes
Before jumping to any conclusions, it’s crucial to systematically rule out common problems. Here’s the checklist that was followed:
- Double-checked the wp-config.php file for typos
- Confirmed that the MySQL database had indeed been copied to Bluehost
- Tested database login credentials via phpMyAdmin
- Attempted to create new database users to connect via a simple PHP script
Despite these efforts, all connection attempts failed when using the original MySQL user account. This raised suspicion about how user permissions were handled during the migration process.
Understanding How Bluehost Handles MySQL Users
Bluehost uses cPanel for server management, which separates the database user from the database itself in terms of privileges. Even though a user account may be present and even correctly assigned a database during import, it doesn’t mean the user has the required privileges to interact with that database.
In our case, the MySQL user entry from the previous server existed, but the privileges had not been mapped correctly in Bluehost’s MySQL system.
Symptoms of a Privilege Issue
If you suspect that your issue is related to MySQL user privileges after a migration, these are some common symptoms you might encounter:
- Login to phpMyAdmin using the database user fails, or shows “no permissions”
- WordPress and other database-based CMS platforms cannot connect even with correct credentials
- Creating a new database and assigning the old user doesn’t resolve the issue
- A fresh test user works perfectly when set up via the MySQL Wizard in cPanel
These are clear indicators that, although your user account may exist, it is not properly linked with the correct privileges to the necessary database.
Steps to Repair MySQL User Privileges on Bluehost
The following repair plan was implemented, and it successfully restored full access. These are the exact steps:
- Login to your Bluehost cPanel.
- Navigate to the MySQL Databases section.
- Scroll to the area labeled “Add User to Database”.
- Choose the existing MySQL user from the dropdown.
- Select the correct database from the adjacent dropdown.
- Click “Add”, and you’ll be prompted to assign privileges.
- Tick the box labeled All Privileges and confirm by clicking “Make Changes”.
This effectively re-links the MySQL user and grants them the correct rights to interact with the database. For our client’s site, the changes took effect immediately, and database connections resumed without issue.
Testing Connection Post-Fix
To verify that the problem was indeed resolved, a new PHP script was run using the MySQLi extension:
<?php
$mysqli = new mysqli('localhost', 'dbuser', 'dbpass', 'databasename');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
echo 'Connection successful.';
$mysqli->close();
?>
This script returned: Connection successful. Additionally, WordPress loaded without error, indicating that the database user privileges were now correctly configured.
Image not found in postmetaUnderstanding Why This Happens
Unlike home directories, MySQL user privilege mappings are not always portable. On many shared hosts, especially those using cPanel, MySQL users are managed centrally and cannot be copied like other files during a migration. When you import your database using tools like phpMyAdmin or command-line utilities, the user entries are not automatically linked to the new environment, leading to orphaned accounts with no practical access.
In this case, Bluehost requires manual re-linking of the user accounts to the appropriate databases. Failing to do so results in the infamous “Error Establishing a Database Connection” message, regardless of whether the rest of the environment seems correct.
Expert Recommendations
To avoid facing similar issues in the future, consider the following best practices:
- Use a verified migration plugin or service that includes database user export functions.
- Always verify user-database bindings manually when migrating to or from a shared host that uses cPanel.
- Test your connection with a manual PHP script before assuming the CMS is broken.
- Document your database credentials and roles prior to migration for easier troubleshooting.
Conclusion
Database connection errors can be frustrating and often misleading, especially post-migration. This incident with Bluehost emphasized how the cause wasn’t due to incorrect configuration files or corrupted databases, but rather a gap in privilege transfer protocols. Fortunately, the simple act of manually reassigning privileges through Bluehost’s cPanel restored functionality almost instantly.
As hosting platforms evolve and migrations become increasingly common, understanding these subtle yet impactful issues becomes crucial for developers, administrators, and even casual users managing their own websites.
Final Takeaway
After any website migration, especially to platforms like Bluehost that use cPanel architecture, it is crucial to check and reassign MySQL user privileges. Even if the user and database appear to exist post-migration, without binding them correctly and granting full privileges, your CMS and apps will be unable to connect effectively. This simple oversight can bring an entire site offline—but it’s also easily fixed if spotted early.