MySQL: Bulk Delete Tables by prefix

Source: Internet
Author: User

Want to implement Mysql>drop table like "prefix_%"

There are no commands that are directly available, but can be assembled by MySQL syntax,

 select  CONCAT ( " drop TABLE  , GROUP_CONCAT (table_name),      )  as  statement from   Information_schema.tables  where  table_schema  '  database_name   '  

Then execute the assembled command, such as removing all tables from the Slowquery table that begin with the TMP_:

SELECT '  "; '  as  from WHERE = ' Slowquery '  and  like ' tmp_% ';

Output Result:

Drop Table


Execute it.

Examples of my own reality:

/*Auto-Generate delete dynamic table SQL statement usage: Copy to Query Analyzer to execute, copy the result and execute it OK. */SELECT REPLACE(Group_concat (A.dropsql),',',"') asDropsql from(SELECTCONCAT ('drop table', TABLE_NAME,';') asDropsql fromInformation_schema.tablesWHEREtable_name like 'slavetablemgr%'UNIONSELECTCONCAT ('drop table', TABLE_NAME,';') asDropsql fromInformation_schema.tablesWHEREtable_name like 'deviceplugin_%'UNIONSELECTCONCAT ('drop table', TABLE_NAME,';') asDropsql fromInformation_schema.tablesWHEREtable_name like 'historyrecordhour%'UNIONSELECTCONCAT ('drop table', TABLE_NAME,';') asDropsql fromInformation_schema.tablesWHEREtable_name like 'historyrecordminute%'UNIONSELECTCONCAT ('drop table', TABLE_NAME,';') asDropsql fromInformation_schema.tablesWHEREtable_name like 'historyrecordsecond%') A;

MySQL: Bulk Delete Tables by prefix

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.