Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Table does not exist error, but it does exist

Tags:

Does anyone know under what conditions you can receive an 1146: Table '<database>.<table>' doesn't exist error when your table does, in fact, exist?

I use the same code on 5 servers, only one that I recently rented is showing this error, so I suspect it may be a settings or install error of some kind. I can execute my sql statement from the command line just fine. I can, obviously, see the table from the command line as well. I don't get any connection errors when I establish a connection (I'm using mysqli, btw).

Any help would be appreciated.

exact query:

$sql = "SELECT DISTINCT(mm_dic_word) AS word FROM spider.mm_dictionary WHERE mm_dic_deleted=0"; 
like image 822
Troy Knapp Avatar asked Nov 23 '10 20:11

Troy Knapp


People also ask

How do you check that table is already exists?

IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' AND name='tablename') SELECT 'tablename exists. ' ELSE SELECT 'tablename does not exist.

How do I fix error 1054 in MySQL?

To fix the error above, simply add a quotation mark around the value. You can use both single quotes or double quotes as shown below: INSERT INTO users(username, display_name) VALUES ("jackolantern", 'Jack'); Now the INSERT statement should run without any error.


2 Answers

This just happened to me and after a while I found the answer on a blog article, and wanted to put it here as well.

If you copy the MySQL data directory from /var/lib/mysql to /path/to/new/dir, but only copy the database folders (i.e. mysql, wpdb, ecommerce, etc) AND you do have innodb tables, your innodb tables will show up in 'show tables' but queries on them (select and describe) will fail, with the error Mysql error: table db.tableName doesn't exist. You'll see the .frm file in the db directory, and wonder why.

For innodb tables, it's important to copy over the ib* files, which in my case were ibdata1, ib_logfile0, and ib_logfile1. Once I did the transfer making sure to copy those over, everything worked as expected.

If your my.cnf file contains "innodb_file_per_table" the .ibd file will be present in the db directory but you still need the ib* files.

like image 94
Isaac Avatar answered Sep 17 '22 21:09

Isaac


Using the mysqlcheck would be in order in this case - so you can discard table sanity problems & repair them if neeeded.

like image 22
David Ramirez Avatar answered Sep 17 '22 21:09

David Ramirez