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.