Error
Error Code: 1109

MySQL Error 1109: Table Not Found

📦 MySQL
📋

Description

MySQL Error 1109, "Unknown table '%s' in %s", indicates that the database server cannot locate a table referenced in your SQL query. This typically occurs when the table name is misspelled, the table does not exist in the currently selected database, or the user lacks necessary permissions.
💬

Error Message

Unknown table '%s' in %s
🔍

Known Causes

4 known causes
⚠️
Incorrect Table Name
The table name specified in the SQL query contains a typo or does not match the exact case (on case-sensitive file systems) of an existing table.
⚠️
Table Does Not Exist
The referenced table has either not been created in the database, was dropped previously, or you are looking in the wrong database.
⚠️
Wrong Database Context
The query is being executed while connected to or using a different database where the specified table does not exist.
⚠️
Insufficient Permissions
The user account executing the query lacks the necessary privileges to access or view the specified table, making it appear 'unknown'.
🛠️

Solutions

4 solutions available

1. Verify Database and Table Name Spelling easy

Double-check that the database and table names in your query are spelled correctly and match the actual names in your MySQL instance.

1
Carefully review the SQL statement that produced the error. Pay close attention to the table name and the database name (if specified).
SELECT * FROM your_database_name.your_table_name;
2
Connect to your MySQL server using a command-line client or a GUI tool (like MySQL Workbench, DBeaver, phpMyAdmin).
mysql -u your_username -p
3
List all databases to confirm the existence of the database you intend to use.
SHOW DATABASES;
4
Select the correct database.
USE your_database_name;
5
List all tables within the selected database to verify the table name.
SHOW TABLES;
6
If the spelling is incorrect, correct it in your SQL query and re-execute.

2. Confirm Current Database Context easy

Ensure that you have selected the correct database before attempting to access a table. The error can occur if the table exists but is not in the currently active database.

1
When running SQL queries, you might omit the database name if you've already selected it. If you haven't, the query will look for the table in the default or currently selected database.
SELECT * FROM your_table_name;
2
Connect to your MySQL server.
mysql -u your_username -p
3
Check which database is currently selected. If no database is selected, this command will return NULL.
SELECT DATABASE();
4
If no database is selected or the wrong one is, select the correct database.
USE your_database_name;
5
Re-execute your query after ensuring the correct database is in context.

3. Check Table Existence with SHOW TABLES easy

A direct way to confirm if a table exists in the current database is by using the SHOW TABLES command.

1
Connect to your MySQL server.
mysql -u your_username -p
2
Select the database where you expect the table to be.
USE your_database_name;
3
List all tables in the current database. Look for the table name in the output.
SHOW TABLES;
4
If the table is not listed, it either does not exist in this database, or it's named differently. If it's missing, you might need to create it or restore it.
# Example: If 'users' table is expected but not shown, the table doesn't exist or is misspelled.

4. Investigate Table Creation or Restoration medium

If the table genuinely doesn't exist, it might have been accidentally dropped or never created. This solution involves checking for its existence and potentially restoring it.

1
First, follow the steps in 'Confirm Current Database Context' and 'Check Table Existence with SHOW TABLES' to absolutely verify the table is not present.
USE your_database_name;
SHOW TABLES LIKE 'your_table_name';
2
If the table is indeed missing, check your application's deployment scripts or database migration history to see if the table was intended to be created.
# Review your application's schema creation scripts.
3
If you have backups, attempt to restore the specific table from a recent backup. The method for restoration depends on your backup strategy (e.g., mysqldump, Percona XtraBackup).
# Example using mysqldump to restore a single table:
# mysqldump -u your_username -p your_database_name your_table_name > /path/to/backup/table_backup.sql
# mysql -u your_username -p your_database_name < /path/to/backup/table_backup.sql
4
If the table was never created, you will need to create it using a `CREATE TABLE` statement, ensuring all columns and constraints are correctly defined.
CREATE TABLE your_table_name (
    id INT AUTO_INCREMENT PRIMARY KEY,
    column1 VARCHAR(255),
    column2 INT
);
🔗

Related Errors

5 related errors