开发者

Drop screwed up table in Mysql db

I've managed to corrupt (or something) the 'sessions' table in a mysql db i have (which is called "e_learning_resource_prelive"). This wouldn't be a problem normally as i could just go 开发者_JAVA技巧back to a backup dump of the db. However, the corrupted table seems to be stopping me deleting the database:

> mysqladmin -u root drop e_learning_resource_prelive
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'e_learning_resource_prelive' database [y/N] y
mysqladmin: DROP DATABASE e_learning_resource_prelive failed;
error: 'Unknown table 'sessions''

When i go into the db the sessions table shows up in show_tables (it's the only one there, the mysqladmin drop deleted the rest) but i can't drop it:

mysql> show tables;
+---------------------------------------+
| Tables_in_e_learning_resource_prelive |
+---------------------------------------+
| sessions                              | 
+---------------------------------------+
1 row in set (0.00 sec)

mysql> drop table sessions;
ERROR 1051 (42S02): Unknown table 'sessions'

Can anyone tell me how i can delete this table, or the whole db? I need to delete the db and then rebuild it from my backup dump.


Figured it out, seems kind of obvious now. The dbs all just have a folder which can be deleted like anything else.

sudo rm -r /var/lib/mysql/e_learning_resource_prelive

Thanks anyone who looked, anyway :) max


session is a reserved keyword (http://developer.mimer.com/validator/sql-reserved-words.tml), I think that is why your database is corrupt.

I had the same issue using a reserved keyword (references in my case), and I also had the problem that renaming, dropping or truncating the table was giving an sql error.

To fix this problem, use backtick-characters in the alter table query.

ALTER TABLE `session` RENAME TO newname

This way the query won't fail, and your data are still there (thank god!). I hope someone finds this useful!


Use the GUI interface. There is probably some not-very-printable character in the sessions name.

Or maybe the underlying file on the filesystem was deleted? If so, try creating an empty file named sessions there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜