简体   繁体   English

MYSQL:删除与损坏的数据库有关的所有内容

[英]MYSQL: remove everything related to corrupted database

I had a corrupted database on my development environment that I could not access any more - probably due to a system crash. 我的开发环境中的数据库已损坏,无法再访问-可能是由于系统崩溃。 As I could not DROP the database (I can't remember why - doesnt matter any more now) I just deleted the databases folder in mysql/data. 由于我无法删除数据库(我不记得为什么了-现在不再重要了),我只是删除了mysql / data中的databases文件夹。

This obviously was not a very good idea. 这显然不是一个好主意。 After creating a new database with the same name, there are still some tablespace definitions somewhere in the database. 创建具有相同名称的新数据库后,数据库中仍存在一些表空间定义。 When I try create new tables I get following error: 当我尝试创建新表时,出现以下错误:

Tablespace for table ' database_name . 表' database_name '的表空间。 table_name ' exists. table_name '存在。 Please DISCARD the tablespace before IMPORT. 请在导入前丢弃表空间。

Is there a decent way to get rid of all references/indexes/tablespace information for the given database? 有没有一种好的方法来消除给定数据库的所有引用/索引/表空间信息? When I try to DROP the newly created Database with the same name, I get: "ERROR 2013 (HY000): Lost connection to MySQL server during query". 当我尝试删除具有相同名称的新创建的数据库时,我得到:“错误2013(HY000):在查询期间与MySQL服务器的连接断开”。

when you get to a situation like that, the best thing to do is: 当遇到这种情况时,最好的办法是:

  1. backup your database 备份数据库
  2. delete entire database 删除整个数据库
  3. restore your database from backup 从备份还原数据库

For each table run these two queries: 对于每个表,请运行以下两个查询:

    ALTER TABLE tablename DISCARD TABLESPACE;
    ALTER TABLE tablename IMPORT TABLESPACE;

If there are too many tables just write a script to loop through them using SHOW TABLES and then the two queries above. 如果表太多,只需编写脚本以使用SHOW TABLES然后使用上面的两个查询来循环遍历它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM