MySQL batch Delete tables

Source: Internet
Author: User

MySQL batch Delete tables
During job debugging, overview created a cron scheduled task that is executed once every minute. A table name with time information is generated every minute and you forgot to delete the scheduled task, currently, there are nearly 3000 new tables to be deleted. Since deletion of a single table is slow, you need to delete these tables with time information in batch.
Theory & measuretheory1 log on to the mysql information database and find the tables Table, find all the time-required table names in the database where the table to be deleted is located. 2. splice the queried table names into the form of drop table command data, for example, drop table weekly_with_you_2014_12_28; 3. log on to the mysql yc_market database and execute all the drop commands output in the previous step.

The specific implementation of measure is very simple. You only need to input the following command on the linux terminal: [jiangjianjian @ h6 ~] $ Echo "select concat ('drop table', table_name, ';') from TABLES where TABLE_SCHEMA = 'yc _ market' and table_name like 'Weekly _ with_you_2014 % '; "| mysql-uroot-p123456-h127.0.0.1 information_schema | sed-n'2, $ P' | mysql-uroot-p123456-h127.0.0.1 yc_market

Yc_marke is the sed command in the database where the table to be deleted is located. It is used to skip the first row of all the drop table commands generated because the first row is invalid.

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.