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.

```text
ER_BAD_DB_ERROR: Unknown database 'mydb'
```

## Fix it

1. List the databases that actually exist, using the same credentials:

```bash
mysql -h YOUR_MYSQL_HOST -u appuser -p -e "SHOW DATABASES;"
```

   Expected: a list. Check whether your intended name is there, exactly spelled.

2. If it is missing, create it:

```sql
CREATE DATABASE mydb CHARACTER SET utf8mb4;
```

3. If it exists under a slightly different name, fix `MYSQL_DB` in the client config `env` block. Common: `mydb` vs `mydb_prod`, singular vs plural.

4. 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). `MyDB` and `mydb` differ.
- 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.