Php batch deletes tables with the specified prefix in the database. The prefix _ is used as an example to batch Delete the prefix.
How to Use php to batch Delete All Tables prefixed with prefix _ in the database.
For example, delete all tables with the prefix "prefix.
<? Php // set the database connection information. Database server address, database username, data password mysql_connect ('database host', 'database Username ', 'database password '); // set the queried database name mysql_select_db ('database name'); $ rs = mysql_query ('show tables '); while ($ arr = mysql_fetch_array ($ rs )) {// set the database table prefix to be deleted in batches, for example, prefix _ $ TF = strpos ($ arr [0], 'prefix _'); if ($ TF = 0) {$ FT = mysql_query ("drop table $ arr [0]"); if ($ FT) {echo "$ arr [0] deleted successfully! <Br> ";}}}?>
Operation instance:
Create a new php file and save it as deletedata. php.
For example, if you want to delete the back-end data of www.jb51.net or http://www.bkjia.com/, you can perform the following two steps:
1. Upload the saved deletedata. php file to the root directory of your website;
2. Enter www.jb51.net/deletedata.php?http://www.bkjia.com/deletedata.php in the address bar.
The script displays information about the successful deletion of all tables in the browser.
Mysql Databases batch delete data tables with the same prefix
Create a delete script first
Run the following statement:
Select 'drop table' + name from sysobjects where type = 'U' and name like 'B %'
The query results are displayed, and the query results are copied.
Then run the copied query results in database 123.
Mysql queries all tables with specific prefixes in a database.
Php won't.
In mysql, I will query the table information.
It is queried from information_schema.tables.
The following is an example:
Mysql> SELECT table_name, table_type, engine
-> FROM information_schema.tables
-> WHERE table_schema = 'test'
-> Order by table_name DESC;
-> //
+ -------------------- + ------------ + -------- +
| Table_name | table_type | engine |
+ -------------------- + ------------ + -------- +
| V_sale_report_x | VIEW | NULL |
| V_sale_report | VIEW | NULL |
| Union_tab_2 | base table | InnoDB |
| Union_tab_1 | base table | InnoDB |
| Test_trigger_table | base table | InnoDB |
| Test_tab2 | base table | InnoDB |
| Test_tab | base table | InnoDB |
| Test_main | base table | InnoDB |
| Test_dysql | base table | InnoDB |
| Test_create_tab4 | base table | InnoDB |
| Test_create_tab2 | base table | InnoDB |
| Test_create_tab1 | base table | InnoDB |
| Test_create_tab | base table | InnoDB |
| Sale_report | base table | InnoDB |
| Log_table | base table | InnoDB |
+ -------------------- + ------------ + -------- +
15 rows in set (0.02 sec)