MySQL: how to drop multiple tables using single query?

前端 未结 7 1259
说谎
说谎 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 10:10

    Simple solution without risk of error:

    mysqldump create a file that contains DROP command like

    DROP TABLE IF EXISTS `wp_matable`;
    

    a 'grep' with "DROP TABLE wp_" give us the commands to execute

    so drop is made by theses trhee lines (you can edit drop.sql to check which tables would be dropped before)

    mysqldump -u user -p database > dump.sql 
    grep "DROP TABLE `wp_" dump.sql > drop.sql
    mysql -u user -p database < drop.sql
    
    0 讨论(0)
提交回复
热议问题