mysqlsqlsql-deletemultiple-tables

MySQL: how to drop multiple tables using single query?


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_'


Solution

  • 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;