Quickest way to delete enormous MySQL table

前端 未结 11 2134
半阙折子戏
半阙折子戏 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 12:58

    (As this turned up high in Google's results, I thought a little more instruction might be handy.)

    MySQL has a convenient way to create empty tables like existing tables, and an atomic table rename command. Together, this is a fast way to clear out data:

    CREATE TABLE new_foo LIKE foo;
    
    RENAME TABLE foo TO old_foo, new_foo TO foo;
    
    DROP TABLE old_foo;
    

    Done

提交回复
热议问题