Quickest way to delete enormous MySQL table

前端 未结 11 2068
半阙折子戏
半阙折子戏 2020-12-23 12:28

I have an enormous MySQL (InnoDB) database with millions of rows in the sessions table that were created by an unrelated, malfunctioning crawler running on the same server a

相关标签:
11条回答
  • 2020-12-23 13:14

    Couldn't you grab the schema drop the table and recreate it?

    0 讨论(0)
  • 2020-12-23 13:16

    If you just want to get rid of the table altogether, why not simply drop it?

    0 讨论(0)
  • 2020-12-23 13:16

    We had these issues. We no longer use the database as a session store with Rails 2.x and the cookie store. However, dropping the table is a decent solution. You may want to consider stopping the mysql service, temporarily disable logging, start things up in safe mode and then do your drop/create. When done, turn on your logging again.

    0 讨论(0)
  • 2020-12-23 13:19

    The quickest way is to use DROP TABLE to drop the table completely and recreate it using the same definition. If you have no foreign key constraints on the table then you should do that.

    If you're using MySQL version greater than 5.0.3, this will happen automatically with a TRUNCATE. You might get some useful information out of the manual as well, it describes how a TRUNCATE works with FK constraints. http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

    EDIT: TRUNCATE is not the same as a drop or a DELETE FROM. For those that are confused about the differences, please check the manual link above. TRUNCATE will act the same as a drop if it can (if there are no FK's), otherwise it acts like a DELETE FROM with no where clause.

    0 讨论(0)
  • 2020-12-23 13:20

    Have you tried to use "drop"? I've used it on tables over 20GB and it always completes in seconds.

    0 讨论(0)
提交回复
热议问题