Skip to content

Shiftora Pro is free. Pull or push everything: database, media, plugins, themes and must-use plugins.

Get Pro For Free
Get Pro For Free Sign in

Error Establishing a Database Connection After Migrating

Guide 5 min read

The “Error establishing a database connection” message means WordPress could not open a connection to its database server, or could not select the database it expects. After a migration it almost always comes from wp-config.php still holding values from the old server, not from the data you moved.

Why the migration is not the cause

A database pull moves tables and media. It does not touch wp-config.php, so the destination keeps its own database name, user, password and host. If the local site used localhost with a port or a socket, and the live server expects a different host name, WordPress fails on the first request. The same happens when the live database user was never created with the right privileges.

Steps

  1. Read the exact error in the server’s error log. MySQL or MariaDB usually names the cause: “Access denied for user” means the user or password is wrong, “Unknown database” means the database name is wrong, and “Can’t connect” points to the host, port or socket.
  2. Open wp-config.php on the destination and check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare them with the values in your host’s control panel. Do not copy the local values across.
  3. Confirm the database exists. Open the host’s database list and check that the name matches DB_NAME exactly, including case if your host is case sensitive.
  4. Confirm the database user has privileges on that database. A user with no grants on the database produces the same symptom as a wrong password.
  5. Check DB_HOST. Many hosts use localhost. Some use a separate host name, a host with a port number or a socket path. Ask your host for the value rather than guessing. Local sites often use a port or socket, which fails on a live server.
  6. Check the table prefix. The $table_prefix value in wp-config.php must match the prefix of the tables you moved. A wrong prefix usually shows as a working connection with missing content, not as this error, so check it once the connection works.
  7. Check the server itself. Confirm the database service is running, that the disk is not full and that the connection limit has not been reached. Your host’s status page or support can confirm this quickly.
  8. Reload the site. If the migration stopped partway, the database may be incomplete. Read the migration log and check that the tables you expected are present before you resume a run.
  9. Test the front page and the admin login once the connection works.
Shiftora review screen listing the selection before a run
Review your selection, then run.

When the connection works but the site does not

If the error clears and the site still fails, the connection was not the whole problem. Check the table prefix next, then check that the tables you expected are present. A pull that stopped halfway can leave the core tables complete and the content tables partly written. Compare the table list on the server with the table list in the migration log. Missing tables mean the run did not finish. Read the log, fix the cause, then run it again from the same source. Also remember that a table you unticked before the run will be missing by design, and that is not an error.

Watch for a second kind of failure. A caching plugin or a server-side cache can keep serving the error page from an earlier request. Clear the caches on the server and in the browser, then reload.

Some hosts put the database elsewhere

On some hosts the database runs on a separate server. In that case DB_HOST is that server’s address, not localhost, and a firewall can block connections from the web server. Ask your host for the exact host name and port, and ask whether the database accepts connections from the web server’s address. If you use a managed host with a control panel, the database settings are usually shown there, not in a file you edit. Test the new values on the front page before you change anything else.

Keep a record of the working values

Once the site is up, write down the working DB_NAME, DB_USER, DB_HOST and table prefix. Store the note with your backup, not inside the site, so it survives a restore. The next migration asks for the same values, and a note saves you from guessing them again from an error message.

The Shiftora documentation at https://shiftora.devsync-agency.com/documentation/ is the reference for the migration log. The free plugin is listed at https://wordpress.org/plugins/shiftora/.

Check that the fix holds

Once the site loads, check it again the next day. A connection that works after one request can still fail under load, if the database server has a connection limit that a busy site reaches. Watch the error log for the same message over a day. If it returns, the cause is on the server, not in the migration, so take the log to your host.

FAQ

Does Shiftora overwrite wp-config.php?
No. A pull moves database tables and media. The destination’s wp-config.php stays as it was, which is why its database values must be correct before you test the site.

Why does the error show up only on the live server?
Local uses its own host, port or socket and its own user. The live server needs the values from its own control panel, and those are usually different.

Can a plugin fix this?
Not when WordPress cannot connect to the database. Fix wp-config.php or the database settings at the host first. Plugins only run once WordPress has a working connection.

Next step: save a copy of the working wp-config.php on the destination before you change any value in it.

Get Shiftora Pro For Free

Pro is free while we launch. Confirm your email and we send the download and your license key.

No card needed. Your license arrives by email right after you confirm.