⚠️ Error Establishing a Database Connection After Migration in WordPress (How to Fix Safely)
⚠️ Exact error
“Error establishing a database connection”

🖥️ Platform
WordPress (self-hosted)
🧭 Introduction
This error commonly appears after a WordPress site is migrated to a new hosting provider, server, or domain. Although the site files are present on the new server, WordPress cannot connect to the database, which is why users need to fix Error Establishing a Database Connection After Migration in WordPress.
When this happens, both the website and the admin area stop working. In most cases, the database still exists and the data is safe—the issue is simply a broken connection that needs to be corrected.
📑 Table of Contents
- 📌 Quick cause summary
- ❓ Why this happens after migration
- 🔧 Step-by-step safe fixes
- Step 1: Confirm the database was actually imported
- Step 2: Verify wp-config.php points to the new database
- Step 3: Check database user permissions
- Step 4: Confirm the correct database host (DB_HOST)
- Step 5: Verify the database table prefix
- Step 6: Repair the database (only if WordPress prompts it)
- 🔄 After the site loads again
- 🚫 What NOT to do
- ⛔ If the issue persists
- 📄 Factual summary
- ❓FAQ
📌 Quick cause summary
After migration, WordPress shows this error when it is still pointing to old database details, the database was not imported correctly, or the new hosting environment requires different connection or permission settings.
❓ Why this happens after migration
A WordPress site is made up of two essential parts:
- Files – WordPress core, themes, plugins, and media
- Database – Stores posts, pages, users, and site configuration
During migration, both parts must be moved and correctly reconnected.
This error occurs when:
- The database was not fully imported
- WordPress is still using old database credentials
- The database user exists but is not allowed to access the database
- The new host uses a different database server address
- The imported database tables use a different prefix
Any one of these breaks authentication between WordPress and the database.
How to Fix Error Establishing a Database Connection After Migration in WordPress
🔧 Step-by-step safe fixes
(Start at Step 1 and stop as soon as the site loads again.)
✅ Step 1: Confirm the database was actually imported
What this checks:
Whether your site’s data exists on the new server.
What is the database?
The database stores all WordPress content such as posts, pages, users, and settings.
How to check:
- Log in to your hosting control panel
- Open phpMyAdmin or Database Management
- Select the database assigned to the migrated site
What you should see:
- A list of tables (containers of data)
- Table names like wp_posts, wp_users, wp_options
- The database should not be empty
If the database exists but contains no tables, the migration did not complete and WordPress has nothing to connect to.
Risk: None
🔑 Step 2: Verify wp-config.php points to the new database
What this checks:
Whether WordPress is trying to connect to the correct database on the new host.
What is wp-config.php?
It is a configuration file that tells WordPress which database to use, which user can access it, and which password to authenticate with. (WordPress documentation)
What to do:
- Open File Manager or connect via FTP
- Open your site’s main folder (commonly public_html)
- Locate wp-config.php
- Download a copy as a backup
Open the file and find:
define( 'DB_NAME', 'database_name_here' ); define( 'DB_USER', 'username_here' ); define( 'DB_PASSWORD', 'password_here' );
What must be true:
- DB_NAME matches the database on the new host
- DB_USER exists on the new host
- DB_PASSWORD matches the database user password
If the password is unknown:
- Reset the database user password in the hosting panel
- Update DB_PASSWORD to match exactly
💡 Important editing note:
WordPress reads this file exactly as written. Even a single extra space, missing quotation mark, or accidental pasted character can break the connection. When copying values, paste them carefully and avoid spaces before or after the quotes.
Save the file and reload the site.
Risk: Low (safe with backup)
🔐 Step 3: Check database user permissions
What this checks:
Whether the database user is allowed to access the database.
After migration, database users are often created but not assigned.
How to check:
- Open database user management in the hosting panel
- Ensure the user is assigned to the database
- Confirm all privileges are enabled
Without proper permissions, WordPress cannot read or write data even if credentials are correct.
Risk: Low
🌐 Step 4: Confirm the correct database host (DB_HOST)
What this checks:
Where the database server is located on the new host.
In wp-config.php, find:
define( 'DB_HOST', 'localhost' );
Important migration detail:
While many hosts use localhost, some hosting environments use a specific IP address or a custom database server name. In such cases, localhost will fail even if the database name, user, and password are correct.
What to do:
- Check the new hosting provider’s documentation or database settings
- Change this value only if the host explicitly specifies a different one
Save the file and reload the site.
Risk: Low (single-line, fully reversible)
🗂️ Step 5: Verify the database table prefix
What this checks:
Whether WordPress is looking for the correct tables inside the database.
What is a table prefix?
It is the text before table names, such as wp_ in:
wp_postswp_users
In wp-config.php, locate this existing line:
$table_prefix = 'wp_';
⚠️ Do not add a new line. This line already exists.
How to verify:
- Open phpMyAdmin
- Select the database
- Look at the table names
What must match:
- If tables start with
wp_, the prefix must bewp_ - If tables start with
abc_, the prefix must beabc_
If they do not match:
- Edit only the value in $table_prefix
- Save the file
- Reload the site
Do not rename database tables and do not add a second prefix line.
Risk: Low
🛠️ Step 6: Repair the database (only if WordPress prompts it)
Use this step only if /wp-admin/ reports damaged or missing tables.
- Back up wp-config.php
- Add this line just above the “stop editing” comment:
define( 'WP_ALLOW_REPAIR', true );
- Visit:
/wp-admin/maint/repair.php
- Click Repair Database
- Remove the line immediately after completion
⚠️ Warning:
Leaving repair mode enabled allows anyone to access the repair tool.
Risk: Medium if left enabled
🔄 After the site loads again
Once the site starts working:
- Perform a hard refresh to ensure you are not seeing a cached error page
Windows/Linux: Ctrl + F5
macOS: Cmd + Shift + R
Browsers sometimes temporarily display a cached error even after the issue is fixed.
🚫 What NOT to do
After migration, avoid these actions:
- Do not delete the database
- Do not reinstall WordPress immediately
- Do not guess database server values
- Do not repeatedly try random passwords
- Do not restore old backups without understanding the failure
These actions often cause permanent data loss.
⛔ If the issue persists
If:
- The database exists with tables
- Credentials and permissions are correct
- DB_HOST is verified
Then the migration itself may be incomplete or restricted by the new host. In such cases, a structured approach helps fix Error Establishing a Database Connection After Migration in WordPress without risking data loss, but final resolution may require hosting-level intervention or a verified re-migration.
📄 Factual summary
This guide explains the database connection error that occurs specifically after a WordPress migration and how to fix Error Establishing a Database Connection After Migration in WordPress. The issue is most often caused by incomplete database imports, mismatched credentials, missing user permissions, incorrect database host values, or table prefix mismatches. Safe resolution focuses on verification and alignment rather than destructive fixes.
❓ FAQ
Is my data lost after migration?
No. In most cases, the database still exists but WordPress cannot access it.
Do I need technical knowledge to fix this?
No advanced knowledge is required if the steps are followed carefully and in order.
Should I migrate again immediately?
Only after confirming the database and configuration cannot be corrected.
🔗 Related guide
If this error is not related to a recent migration, see:
How to Fix “Error Establishing a Database Connection” in WordPress (Safely)
