There was a problem loading the comments.

Database Connection Error After Moving a WordPress Site.

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Just moved, migrated or restored your WordPress site and now see a database error? Work through this checklist on the new server.

WordPressSite migrationBackup restoreShared hosting & VPSโฑ About 15 minutes

Quick answer: After a move, "Error establishing a database connection" almost always means wp-config.php still holds the old server's database details, or the database was not fully imported on the new server. Create the database and user on the new server, import the full backup, then update all four database values in wp-config.php to match the new server.

Which Guide Do You Need?

You are here

The error started after you moved, migrated or restored the site

Nothing movedThe error appeared on a site that was working โ†’
VPS or dedicated serverYou need server-level checks: logs, service, permissions โ†’

Why Moving a Site Causes This Error

A WordPress site has two parts: the files (including wp-config.php) and the database (posts, pages, settings and users). Copying the files is not enough. The database must be recreated on the new server, and wp-config.php must be told where it is. If any of the four connection details still point to the old server, WordPress cannot connect.

What often goes wrong in a move Step
Your domain still points to the old server Step 1
The database import stopped part-way or failed Step 2
The database user was not created or not assigned on the new server Step 3
wp-config.php still has the old name, user, password or host Step 4

Before You Start

๐Ÿ“ฆ Keep the database backup (.sql or .sql.gz file) from the old server. If the old hosting is still active, do not cancel it until the new site works.
๐Ÿ”‘ Have access to the new server's control panel (SolidCP, WebsitePanel or Plesk) and its File Manager or FTP.

1Check Which Server Is Showing the Error

After a move, your domain can keep pointing to the old server for some hours while DNS changes spread. The error may come from the old site, for example if its database was already deleted.

  1. Open Command Prompt or a terminal and run:
    nslookup yourdomain.com
  2. Compare the address shown with the IP address of your new SoftSys server (in your welcome email or control panel).
  3. If it shows the old server's address, the DNS change has not reached you yet. Wait, or update the domain's DNS records if you have not done so.

๐Ÿ’ก Tip: To test the new server before DNS changes, add a line to your computer's hosts file that maps your domain to the new server's IP address. Remove the line when you are finished.

2Confirm the Database Was Fully Imported

  1. On the new server, open phpMyAdmin from your control panel and select the database.
  2. Check that the WordPress tables are listed, such as wp_options, wp_posts and wp_users. Your tables may start with a different prefix than wp_.
  3. If the database is empty or tables are missing, import the backup again.
Import problem What to do
Unknown collation: 'utf8mb4_0900_ai_ci' The backup came from MySQL 8 and the new server runs an older MySQL or MariaDB. Open the .sql file in a text editor, replace every utf8mb4_0900_ai_ci with utf8mb4_unicode_ci, save and import again.
File too large, or the import times out Upload a compressed .sql.gz file. On a VPS, import from the command line with the mysql client. On shared hosting, open a support ticket and we can help with the import.
Table ... already exists An earlier attempt partly worked. Import into a new, empty database, or remove the existing tables first (only if nothing else uses that database).

3Create the Database User on the New Server

Database users are not copied with the backup. They must exist on the new server.

  1. In the database section of your control panel, create a database user (or use an existing one) and set a strong password.
  2. Assign the user to the database with full permissions.
  3. Write down the exact database name, username and password shown in the panel. Some panels add a prefix to names, so they may not match the names on the old server.

4Update wp-config.php for the New Server

  1. Open wp-config.php in the site's main folder on the new server.
  2. Replace all four values with the details from Step 3:
    define( 'DB_NAME', 'new_database_name' );
    define( 'DB_USER', 'new_database_user' );
    define( 'DB_PASSWORD', 'new_database_password' );
    define( 'DB_HOST', 'localhost' );
  3. Set DB_HOST to localhost, unless your SoftSys welcome email or control panel gives a different database server name. Do not keep the old host's server name.
  4. Save the file and reload the site.

โš ๏ธ Password with a quote mark? If the password contains a single quote ('), it ends the text early and breaks the line. Put a backslash before it (\'), or choose a new password without quote marks.

Seeing the WordPress Install Screen Instead?

If the error is gone but WordPress asks you to install it again, it is connected to the database but cannot find its tables. The table prefix in wp-config.php does not match the imported tables.

  1. In phpMyAdmin, note the start of the table names, for example wpab_options means the prefix is wpab_.
  2. In wp-config.php, make the prefix line match:
    $table_prefix = 'wpab_';
  3. Do not run the installer: it would create a new, empty site.

Verify the Move

โœ”๏ธ The move is complete when:

  1. nslookup shows the new server's IP address.
  2. The home page and a few inner pages load, with your latest posts.
  3. You can log in to /wp-admin with your usual WordPress username and password.

Only cancel or delete the old hosting once all three are true.

Frequently Asked Questions

I copied all the files. Why is the database not there?

The database is stored by the database server, not in the site's files. It has to be exported from the old server and imported on the new one as a separate step.

The site works for me but others still see the error. Why?

Their computers are still reaching the old server because DNS changes take time to spread, often a few hours and sometimes up to 48 hours. Keep the old hosting running until the change has spread.

Can SoftSys help me move my WordPress site?

Yes, open a support ticket to ask about help with the move, including the database import.

Still seeing the error after the move?

Tell us your domain, where the site was moved from, and which step above failed. We will help you get it connected.

Open a Support Ticket ยป

Related Articles

How to Fix 'Error Establishing a Database Connection' in WordPress โ†’
WordPress Database Connection Error: Advanced VPS Diagnostics โ†’
How to Fix the HTTP 500 Internal Server Error in WordPress โ†’

Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting