MySQL: how to drop multiple tables using single query?

前端 未结 7 1342
说谎
说谎 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:51

    Just sharing one of the solutions:

    mysql> SELECT CONCAT( "DROP TABLE ",
    GROUP_CONCAT(TABLE_NAME) ) AS stmt

    FROM information_schema.TABLES

    WHERE TABLE_SCHEMA = "your_db_name" AND TABLE_NAME LIKE "ur condition" into outfile '/tmp/a.txt';

    mysql> source /tmp/a.txt;

提交回复
热议问题