Members Login
Username 
 
Password 
    Remember Me  
Post Info TOPIC: MySQL table shows in list but SELECT says table doesn't exist
Alejandro Martínez

Date:
MySQL table shows in list but SELECT says table doesn't exist
Permalink   


 

Hi experts,

I created a table in MySQL 5.7.

When I run:

 
 
SHOW TABLES;
 

I can see the table name in the result.

But when I run:

 
 
SELECT * FROM mytable;
 

It gives me:

 
 
Error Code: 1146. Table 'database.mytable' doesn't exist
 

If I try to DROP TABLE mytable;
It says:

 
 
Error Code: 1051. Unknown table
 

How can a table exist and not exist at the same time?
How do I fix this so I can recreate it?

Using MySQL Workbench 6.3 on Windows 10.

Thanks.

 



__________________
gary_futch

Date:
Permalink   

This usually means youre not actually querying the same schema you think you are. SHOW TABLES; only shows tables in the currently selected database. If Workbench reconnects or the default schema changes, SELECT * FROM mytable; may be running against another database, which explains the 1146 error.

Run:

SELECT DATABASE();

and confirm it matches the schema where you created the table. Or fully qualify it:

SELECT * FROM database.mytable;
DROP TABLE database.mytable;

Another common cause on Windows is case sensitivity. The table might have been created as MyTable and you're querying mytable. Even on Windows, depending on lower_case_table_names, mismatched case can cause weird behavior.

 

Worst case scenario: the .frm file exists but the underlying InnoDB metadata is corrupted, so it shows up in SHOW TABLES but cant actually be accessed. If thats the case, check SHOW ENGINE INNODB STATUS; and the MySQL error log. If it turns out to be dictionary corruption, you may need to drop the orphaned table files manually or use a recovery tool like Stellar Repair for MySQL to extract data before recreating the table.



__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.

Tweet this page Post to Digg Post to Del.icio.us


Create your own FREE Forum
Report Abuse
Powered by ActiveBoard