删除 Mysql 数据库中搞砸的表

发布于 2024-08-16 21:04:57 字数 981 浏览 3 评论 0原文

我已经设法损坏(或其他)我拥有的 mysql 数据库中的“会话”表(称为“e_learning_resource_prelive”)。通常这不会成为问题,因为我可以返回数据库的备份转储。然而,损坏的表似乎阻止我删除数据库:

> 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''

当我进入数据库时​​,会话表显示在 show_tables 中(这是唯一的一个,mysqladmin drop 删除了其余的),但我无法删除它:

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'

可以有人告诉我如何删除这个表或整个数据库?我需要删除数据库,然后从备份转储中重建它。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月静好 2024-08-23 21:04:57

想通了,现在似乎很明显了。数据库都只有一个文件夹,可以像其他任何东西一样删除。

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

感谢任何看过的人,无论如何:)
最大限度

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

咆哮 2024-08-23 21:04:57

session 是保留关键字 (http://developer. mimer.com/validator/sql-reserved-words.tml),我认为这就是您的数据库损坏的原因。

我使用保留关键字(在我的例子中是 references)也遇到了同样的问题,而且我还遇到了重命名、删除或截断表会产生 sql 错误的问题。

要解决此问题,请在 alter table 查询中使用反引号字符。

ALTER TABLE `session` RENAME TO newname

这样查询就不会失败,并且您的数据仍然存在(感谢上帝!)。我希望有人觉得这很有用!

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!

番薯 2024-08-23 21:04:57

使用 GUI 界面。 sessions 名称中可能存在一些不太可打印的字符。

或者文件系统上的底层文件可能已被删除?如果是这样,请尝试在其中创建一个名为 sessions 的空文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文