MySQL DROP all tables, ignoring foreign keys

前端 未结 24 2754
醉梦人生
醉梦人生 2020-12-02 03:44

Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there?

24条回答
  •  隐瞒了意图╮
    2020-12-02 04:07

    DB="your database name" \
        && mysql $DB < "SET FOREIGN_KEY_CHECKS=0" \
        && mysqldump --add-drop-table --no-data $DB | grep 'DROP TABLE' | grep -Ev "^$" | mysql $DB \
        && mysql $DB < "SET FOREIGN_KEY_CHECKS=1"
    

提交回复
热议问题