MySQL MCP: ER_BAD_DB_ERROR Unknown database (fix MYSQL_DB or create it)
Fixes the MySQL MCP server failing with ER_BAD_DB_ERROR: Unknown database. Auth succeeded but the MYSQL_DB name does not exist on the server. The fix is creating the database or correcting the name. Use when auth works but the database is rejected; not for access-denied errors.
TL;DR: Auth worked, but the database named in MYSQL_DB does not exist on that MySQL server. Either create it with CREATE DATABASE, or fix the typo in the name. Then restart the client.
ER_BAD_DB_ERROR: Unknown database 'mydb'Fix it
- List the databases that actually exist, using the same credentials:
mysql -h YOUR_MYSQL_HOST -u appuser -p -e "SHOW DATABASES;"Expected: a list. Check whether your intended name is there, exactly spelled.
- If it is missing, create it:
CREATE DATABASE mydb CHARACTER SET utf8mb4;- If it exists under a slightly different name, fix
MYSQL_DBin the client configenvblock. Common:mydbvsmydb_prod, singular vs plural.
- Restart the MCP client.
Expected: the server connects to the database and tools work.
When to use this
- Auth succeeds (no access-denied error) but every call fails with
Unknown database. - You recently renamed things or copied the config from another environment.
When NOT to use this
- The error is
ER_ACCESS_DENIED_ERROR. Fix credentials first. - The error is
ER_NO_SUCH_TABLE. The database exists; a table inside it does not.
Compatibility
- benborla/mcp-server-mysql (MYSQL_DB env config).
- MySQL 5.7, 8.x, MariaDB.
Why it happens
The MCP server passes MYSQL_DB straight to the MySQL driver as the default database. MySQL checks it at connect time and rejects unknown names. Configs copied between dev, staging, and prod often carry a stale database name while the host and credentials get updated.
Edge cases
- Database names are case-sensitive on Linux (filesystem-dependent).
MyDBandmydbdiffer. - If the database exists but the user lacks privileges on it, you get access denied, not unknown database. Different fix.
- Some setups expect the server to create the schema. It does not. Create it first, then connect.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.