Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping a table in MySQL (3.23.58) with a special character in the tablename

Yes this is an old db (we are in the process of migrating). Somehow, phpMyAdmin let a user create a table with a ' in it.

name: type_save'

But, I cannot seem to drop that table now. I have tried this from the commandline:

mysql> drop table "type_save\'";
ERROR 1064: You have an error in your SQL syntax near '"type_save\'"' at line 1                                                                          

mysql> drop table "type_save'";
ERROR 1064: You have an error in your SQL syntax near '"type_save'"' at line 1    


mysql> drop table `type_save'`;
'>                                                                                      

How do you properly escape this?

Thanks...

like image 743
bgarlock Avatar asked Nov 09 '10 18:11

bgarlock


3 Answers

According to Does MySQL allows to create database with dot? you use backticks to quote the name, as in

drop table `type_save'`

Try that and see if it helps.

like image 127

Try this:

mysql> drop table `type_save'`;

Note: "mysql>" is only the command prompt.

Character is ` (reverse apostrophe or left single quote).

like image 35
Pablo Santa Cruz Avatar answered Sep 24 '22 15:09

Pablo Santa Cruz


It's MySQL 3.x, so it's very likely MyISAM (or even ISAM). Since the normal way to drop the table isn't working (since you say it crashes the server), and if it's MyISAM/ISAM, just delete the relevant .MYI, .MYD, and .frm files straight from the filesystem, or move them elsewhere if you need to preserve them for some reason. Then do a flush tables. You don't even need to shut down the server (at least on Unix, on Windows the file may be in use and Windows may not let you delete it. Flush tables may help).

Do not do this if its InnoDB, only ISAM or MyISAM.

If its InnoDB, I'm afraid you may have a dump/reload in your future.

And have backups, of course. Always have backups.

like image 29
derobert Avatar answered Sep 24 '22 15:09

derobert