MySQL: how to drop multiple tables using single query?

前端 未结 7 1377
说谎
说谎 2020-12-15 09:13

I want to drop multiple tables with ease without actually listing the table names in the drop query and the tables to be deleted have prefix say \'wp_\'

7条回答
  •  星月不相逢
    2020-12-15 09:58

    For the great mysqldump solution it's better to use the option --skip-quote-names

    mysqldump --skip-quote-names -u user -p database > dump.sql 
    grep "DROP TABLE wp_" dump.sql > drop.sql
    mysql -u user -p database < drop.sql
    

    You get rid of backticks in table names. The grep part won't work in some enviroments with the backticks.

提交回复
热议问题