Guide Databases & MySQL

How to fix "unknown database" errors

The database name your application is asking for does not exist, at least not under that exact name, on that server.

Updated 7 min read Beginner

An "unknown database" error is more specific than most database failures, and that is good news: it means your connection to the server itself succeeded, and MySQL is simply telling you that the particular database name your application asked for does not exist under that exact spelling on that server. The fix is almost always about the name, not about anything more serious.

What the error is actually telling you

The message usually names the database directly, in a form close to Unknown database 'database_name'. That name came straight from your application's own configuration, which means the credentials got as far as reaching MySQL and being accepted; MySQL just could not find a database matching what it was asked for. This rules out a whole category of connection problems and narrows things down to the name itself.

Cause 1: the name in your configuration is slightly wrong

This is the most common cause by a wide margin. Open your application's configuration, for WordPress that is DB_NAME in wp-config.php, and compare it character by character against the database name shown in the databases section of your control panel. A single character out, a stray space, or the wrong case in a case-sensitive setup is enough to produce this exact error while everything else about the connection is correct.

Cause 2: the account prefix is missing

Many control panels automatically prepend your account name to whatever you type when creating a database, so a database you named shop might actually exist on the server as account_shop. If your configuration has just the part you typed rather than the full prefixed name shown after saving, MySQL genuinely cannot find a database by that shorter name, because it does not exist. Always copy the name exactly as your control panel displays it, not as you originally typed it.

Cause 3: the database was never actually created

If this is a fresh setup rather than something that used to work, check that the database creation step actually completed. An interrupted installer, a step skipped by mistake, or a database creation that silently failed for an unrelated reason all leave you with an application configured to use a database that was never made in the first place. Creating a MySQL database and user covers the correct order to do this in.

Cause 4: you are pointed at the wrong server

If this error appeared during or shortly after a migration, check the host value in your configuration as well as the database name. A configuration still pointing at localhost after files have moved to a new server, while the database itself now lives elsewhere, will report the database as unknown even if a database with that exact name exists — just not on the server the application is actually asking. See why the database host is "localhost" and moving a database to a new server if a migration is involved.

Cause 5: the database was deleted or renamed

If a database that previously existed no longer appears in your control panel at all, it has either been removed deliberately, removed by mistake, or renamed as part of some other change. If you have a recent backup, creating a fresh database with the correct name and importing that backup into it resolves this quickly; if you are not sure whether a backup exists, check with whoever manages the account before assuming the data is gone, since the error itself only ever means the database cannot be found, not that any data has been destroyed.

Cause 6: a typo in the database name itself, not just your configuration

It is worth checking the database name in your control panel too, not only your configuration file. If the database was created with a typo in the first place, for instance an extra letter or a transposed pair of characters, then a configuration that matches your own notes perfectly can still be wrong, because it is your notes that were wrong rather than the file you are editing. Read the name directly off the control panel screen rather than from memory, a README, or an old email, and copy it from there into your configuration to remove this possibility entirely.

Testing the name directly

To check independently of your application whether a given database name actually exists and is reachable, a short standalone script removes the guesswork:

<?php
$link = @mysqli_connect('localhost', 'DB_USER', 'DB_PASSWORD', 'DB_NAME');
if (!$link) {
    die('Failed: ' . mysqli_connect_error());
}
echo 'Connected to DB_NAME successfully.';

Fill in your own values and upload it to your site temporarily. A successful connection confirms the name and credentials are correct together, which points the problem back at your application's own configuration rather than the database itself.

Delete the test file afterwards

It contains your database password in plain text at a URL anyone could reach if they guessed it. Remove it as soon as you have your answer.

If none of this resolves it

List every database on the account from the databases section of your control panel and compare that list, name for name, against what your application is configured to use. A mismatch almost always shows up doing this side by side, even when re-reading the configuration file alone has not caught it. If you have checked every database on the account and none of them match what your application expects, contact us with the exact name your application is trying to reach, and we can confirm what actually exists on the account from our side.

Related reading