MySQL “Unknown database”: create it with the right charset
List the real databases, then create the missing one with the right charset.
Run SHOW DATABASES to see what exists. If yours is missing, create it: CREATE DATABASE mydb CHARACTER SET utf8mb4;. Also check spelling and case — mydb and MyDB differ on Linux.
Try these fixes in order
List existing databases
See the exact names the server knows about, including case.
mysql -u root -p -e "SHOW DATABASES;"Create the database
utf8mb4 is the modern default charset; set it explicitly so the new database does not inherit a legacy default.
mysql -u root -p -e "CREATE DATABASE mydb CHARACTER SET utf8mb4;"Verify it exists
Confirm the new database appears in the list.
mysql -u root -p -e "SHOW DATABASES LIKE 'mydb';"Connect to it
You should connect without ERROR 1049.
mysql -u root -p mydb -e "SELECT DATABASE();"Interpret what you see
Fresh server or new environment
What it suggests: Database names are identifiers on the server; a name that does not exist there produces this error even if your app config is otherwise right.
Next check: Run SHOW DATABASES to see what actually exists.
It works on macOS/Windows but fails on Linux
What it suggests: On case-sensitive filesystems, MyDB and mydb are different databases.
Next check: Compare the exact spelling and case against SHOW DATABASES output.
The database exists according to a colleague
What it suggests: The client may be connecting to the wrong server (for example a local dev server instead of the intended one).
Next check: Check SELECT @@hostname and the connection parameters.
Why this happens
- The database was never created on this server.
- The name is misspelled or has different letter case than the actual database.
Still not working?
Do not create the database by making a directory under the data dir by hand; the server needs its internal dictionary entries too. Always use CREATE DATABASE.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.