How to fix ERROR 1102: Incorrect database name in MySQL

MySQLBEGINNERLOWUpdated Dec 22, 2025ยท 162 views

ERROR 1102 occurs when MySQL encounters an invalid or non-existent database name in your query. This typically happens due to typos, special characters, reserved words, or databases that no longer exist.

Quick fix

Fixes 1102

SHOW DATABASES;
  1. Verify the database exists
  2. Check for typos in the database name
  3. Handle special characters with backticks
  4. Use backticks for reserved keywords
mysql โ€” error
SHOW DATABASES;
ERROR 1102: Incorrect database name

What this error means

ERROR 1102 (SQLSTATE: 42000) with symbol ER_WRONG_DB_NAME is a MySQL server error that indicates the database name specified in your SQL statement is invalid or does not exist. MySQL has strict naming rules for database identifiers: they must be 64 characters or less, cannot contain ASCII NUL or supplementary characters, and cannot end with spaces. When MySQL encounters a database name that violates these rules or doesn't match any existing database on the server, it raises ERROR 1102. This error is a syntax/access validation error that prevents the query from executing, making it impossible to select or manipulate data in that database. The error message format is "ERROR 1102: Incorrect database name '%s'" where '%s' shows the problematic database name. This helps identify exactly which name was invalid.

Typical symptoms

  • Database queries fail immediately with "ERROR 1102" before executing
  • Connection attempts fail when specifying an invalid default database
  • Migration tools or backup scripts report ERROR 1102 for certain databases
  • MySQL upgrade commands fail with ERROR 1102 referencing system directories like "#mysql50#"
  • Applications cannot connect when database name contains special characters or spaces
  • Scripts work on one server but fail on another with the same database name

Common causes

  1. Typo in database name - misspelled name in USE statement or connection string
  2. Database does not exist - trying to access a database that was never created or was deleted
  3. Invalid characters in database name - using special characters like hyphens (-), spaces, or dots (.) without quoting
  4. Reserved MySQL keyword used as database name - using words like CREATE, SELECT, or DROP without backticks
  5. Case sensitivity mismatch - on case-sensitive filesystems (Linux), "MyDb" and "mydb" are different
  6. Leading or trailing spaces in database name - spaces at the beginning or end of the identifier
  7. Database name too long - exceeds 64 character limit for MySQL identifiers
  8. Hidden directories in data directory - folders starting with a dot (.) in /var/lib/mysql/ can cause errors during mysql_upgrade
  9. Leftover database directories - database folder remains in /var/lib/mysql/ after the database was dropped
  10. Supplementary or NUL characters - using non-ASCII or unicode supplementary characters in the name

How to fix "ERROR 1102: Incorrect database name"

1Verify the database exists

First, check if the database you're trying to access actually exists on your MySQL server:

sql
SHOW DATABASES;

Look through the output for your database name. If it's not listed, you'll need to create it first:

sql
CREATE DATABASE my_database;

If the database should exist but doesn't appear, verify you're connected to the correct MySQL server (check hostname and port).

2Check for typos in the database name

Review your SQL statement or connection configuration for typos. Common mistakes include:

- Misspelled database names: USE databse; instead of USE database;
- Wrong database selected in connection string
- Copy-paste errors from documentation or configuration files

Compare the name in your query character-by-character with the output from SHOW DATABASES;. Check for:
- Extra or missing letters
- Swapped letters
- Numbers instead of letters (0 vs O, 1 vs l)

3Handle special characters with backticks

If your database name contains special characters like hyphens, spaces, or dots, you must quote it with backticks:

sql
USE `my-database`;
-- or for spaces
USE `my database`;
-- or for dots
USE `my.database`;

This tells MySQL to treat the entire string as an identifier, not as SQL syntax. Without backticks, MySQL interprets hyphens as subtraction operators and spaces as separators.

Best practice: Avoid special characters in database names and use underscores instead:

sql
CREATE DATABASE my_database;
4Use backticks for reserved keywords

If your database name is a MySQL reserved word (CREATE, SELECT, DATABASE, etc.), you must enclose it in backticks:

sql
USE `select`;
USE `database`;
USE `create`;

Without backticks, MySQL interprets these as SQL keywords instead of identifiers, causing ERROR 1102.

Best practice: Avoid using reserved words as database names. If you must use one, always quote it with backticks.

5Fix case sensitivity issues

On Linux and Unix systems, database names are case-sensitive. Windows and macOS are case-insensitive.

If you're migrating between systems, ensure consistency:

sql
-- On Linux, these are THREE different databases:
USE MyDatabase;
USE mydatabase;
USE MYDATABASE;

-- On Windows, they all refer to the same database

Check the actual database names with SHOW DATABASES; and use the exact case:

sql
USE MyDatabase;  -- Matches the output exactly

If moving databases between systems, rename them to lowercase for consistency:

sql
ALTER DATABASE `OldName` MODIFY NAME = new_name;
6Clean up leftover database directories (admin)

If ERROR 1102 appears after deleting a database, a leftover directory in /var/lib/mysql/ might be causing issues.

Warning: This requires MySQL server access and admin privileges.

1. Stop the MySQL server:

bash
sudo systemctl stop mysql
# or on some systems
sudo service mysql stop

2. List contents of the data directory:

bash
ls -la /var/lib/mysql/ | grep "^\.\|^\.\."

3. Move any directories starting with a dot (.) to a backup location:

bash
sudo mv /var/lib/mysql/.directoryname /tmp/mysql-backup/

4. Restart MySQL:

bash
sudo systemctl start mysql
7Fix MySQL upgrade errors with system directories

During mysql_upgrade, you might see ERROR 1102 for system directories like "#mysql50#.ssh":

bash
ERROR 1102: Incorrect database name '#mysql50#.ssh'

This happens when upgrading from MySQL 5.0 and legacy directories remain. The fix:

1. Check what's in the data directory:

bash
ls -la /var/lib/mysql/ | grep "^d"

2. Move the legacy directories:

bash
sudo mv /var/lib/mysql/#mysql50# /tmp/mysql-legacy-backup/

3. Run mysql_upgrade again:

bash
sudo mysql_upgrade -u root -p
8Update connection strings in your application

If you're getting ERROR 1102 from your application, check your database connection configuration:

Common connection string formats:

Node.js / mysql2:

javascript
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'my_database'  // Check this matches exactly
});

Python / mysql-connector:

python
connection = mysql.connector.connect(
  host="localhost",
  user="root",
  password="password",
  database="my_database"  # Must be exactly correct
)

PHP / mysqli:

php
$conn = new mysqli("localhost", "root", "password", "my_database");
// Last parameter is database - verify it exists

Verify:
1. The database exists: SHOW DATABASES;
2. The name matches exactly (including case on Linux)
3. No typos or extra spaces
4. Restart the application after fixing

Advanced notes

MySQL identifier rules: Database names can contain letters, numbers, underscores, and dollar signs, but cannot start with a digit or contain ASCII NUL characters. The maximum length is 64 characters. Reserved words require backticks to be used as identifiers.

Character encoding: Special characters in database names are encoded in the filesystem according to MySQL's character set. Some filenames may contain percent-encoded characters (e.g., %40 for @). This is transparent in queries but matters when manually inspecting /var/lib/mysql/ directories.

Platform differences: Database and table names are case-sensitive on Linux/Unix but case-insensitive on Windows/macOS. This can cause migration issues. It's best practice to use lowercase with underscores for all database names to ensure cross-platform compatibility.

MySQL upgrade issues: When upgrading from older MySQL versions, the upgrade process may encounter ERROR 1102 if leftover system directories (like #mysql50# from MySQL 5.0) exist. These should be removed or moved before running mysql_upgrade.

Performance note: Error 1102 is caught at the parsing stage before query execution, so it has minimal performance impact - the server immediately rejects the query without resource allocation.

Frequently asked questions

What does "1102" mean?
ERROR 1102 (SQLSTATE: 42000) with symbol ER_WRONG_DB_NAME is a MySQL server error that indicates the database name specified in your SQL statement is invalid or does not exist. MySQL has strict naming rules for database identifiers: they must be 64 characters or less, cannot contain ASCII NUL or supplementary characters, and cannot end with spaces. When MySQL encounters a database name that violates these rules or doesn't match any existing database on the server, it raises ERROR 1102.
How do I fix "1102"?
ERROR 1102 occurs when MySQL encounters an invalid or non-existent database name in your query. This typically happens due to typos, special characters, reserved words, or databases that no longer exist.
What causes "1102"?
Typo in database name - misspelled name in USE statement or connection string Database does not exist - trying to access a database that was never created or was deleted Invalid characters in database name - using special characters like hyphens (-), spaces, or dots (.) without quoting
Is the "1102" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading