MySQL bulk delete specified prefix or suffix table

Source: Internet
Author: User

Today suddenly found that we have many tables in the database, suffix named "Copy", is estimated to be a direct copy of the navicat caused, and then to those with the same suffix name of the table to delete, if a choice will be troublesome, the table for more, find a method on the Internet, mainly through SQL statements to delete, Himself on his basis to write a PHP file implementation of 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 needs to be adjusted only need to adjust the "%_copy", according to the table characteristics to be removed to adjust

[2] Delete the table, according to the generated text, after copying, execution can be implemented to delete the table.

2, PHP implementation of the deletion, in fact, the same principle 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.