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.
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.
First, check if the database you're trying to access actually exists on your MySQL server:
SHOW DATABASES;Look through the output for your database name. If it's not listed, you'll need to create it first:
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).
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)
If your database name contains special characters like hyphens, spaces, or dots, you must quote it with backticks:
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:
CREATE DATABASE my_database;If your database name is a MySQL reserved word (CREATE, SELECT, DATABASE, etc.), you must enclose it in backticks:
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.
On Linux and Unix systems, database names are case-sensitive. Windows and macOS are case-insensitive.
If you're migrating between systems, ensure consistency:
-- On Linux, these are THREE different databases:
USE MyDatabase;
USE mydatabase;
USE MYDATABASE;
-- On Windows, they all refer to the same databaseCheck the actual database names with SHOW DATABASES; and use the exact case:
USE MyDatabase; -- Matches the output exactlyIf moving databases between systems, rename them to lowercase for consistency:
ALTER DATABASE `OldName` MODIFY NAME = new_name;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:
sudo systemctl stop mysql
# or on some systems
sudo service mysql stop2. List contents of the data directory:
ls -la /var/lib/mysql/ | grep "^\.\|^\.\."3. Move any directories starting with a dot (.) to a backup location:
sudo mv /var/lib/mysql/.directoryname /tmp/mysql-backup/4. Restart MySQL:
sudo systemctl start mysqlDuring mysql_upgrade, you might see ERROR 1102 for system directories like "#mysql50#.ssh":
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:
ls -la /var/lib/mysql/ | grep "^d"2. Move the legacy directories:
sudo mv /var/lib/mysql/#mysql50# /tmp/mysql-legacy-backup/3. Run mysql_upgrade again:
sudo mysql_upgrade -u root -pIf you're getting ERROR 1102 from your application, check your database connection configuration:
Common connection string formats:
Node.js / mysql2:
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'my_database' // Check this matches exactly
});Python / mysql-connector:
connection = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="my_database" # Must be exactly correct
)PHP / mysqli:
$conn = new mysqli("localhost", "root", "password", "my_database");
// Last parameter is database - verify it existsVerify:
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
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.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL