MySQL DROP all tables, ignoring foreign keys

前端 未结 24 2700
醉梦人生
醉梦人生 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 03:49

    If in linux (or any other system that support piping, echo and grep) you can do it with one line:

    echo "SET FOREIGN_KEY_CHECKS = 0;" > temp.txt; \
    mysqldump -u[USER] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP >> temp.txt; \
    echo "SET FOREIGN_KEY_CHECKS = 1;" >> temp.txt; \
    mysql -u[USER] -p[PASSWORD] [DATABASE] < temp.txt;
    

    I know this is an old question, but I think this method is fast and simple.

提交回复
热议问题