MySQL bulk delete specified prefix or suffix table

Source: Internet
Author: User

Today suddenly found that we have many more tables in the database, suffix named "Copy", is expected to be a direct copy of the navicat caused, and then to those with the same suffix name of the table to delete, assuming that a choice will be very troublesome, the table for many, in the online search method, the Internet mainly through SQL statements to delete. Himself on his basis to write a PHP file implemented by the bulk delete table. In fact the principle is the same.

1. mysql Batch Delete

[1] Get the bulk delete command:

Select CONCAT (' drop table ', table_name, '; ') From Information_schema.tables Where table_name like '%_copy ';
It is necessary to adjust the only need to adjust the "%_copy" can be, according to the characteristics of the table to be removed to adjust

[2] Deletes the table, based on the generated text. After copying. Operation can be achieved by deleting the table.

2, PHP implementation Delete. Actually, the same thing as above.

<?php$con = mysql_connect ("localhost", "root", "" "), mysql_select_db (" Ceshibiao ", $con); $query =" Select CONCAT (' Drop Table ', table_name, '; ')  As Ceshifrom information_schema.tables Where table_name like '%_copy '; "; $cursor = mysql_query ($query), while ($ROW =mysql_fetch_array ($cursor)) {mysql_query ($ROW ["Ceshi"])}?

>


MySQL bulk delete specified prefix or suffix table

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.