1. Execute the select statement first to generate all truncate statements Statement format: select CONCAT('truncate TABLE ',table_schema,'.',TABLE_NAME, ';') from INFORMATION_SCHEMA.TABLES where table_schema in ('数据库1','数据库2'); Take the database named dbname as an example and execute the select statement: mysql> select CONCAT('truncate TABLE ',table_schema,'.',TABLE_NAME, ';') from INFORMATION_SCHEMA.TABLES where table_schema in ('dbname'); +------------------------------------------------------------+ | CONCAT('truncate TABLE ',table_schema,'.',TABLE_NAME, ';') | +------------------------------------------------------------+ | truncate TABLE dbname.ABOUTUSINFO; | | truncate TABLE dbname.ABUTMENT; | | truncate TABLE dbname.ABUTMENTFILE; | | truncate TABLE dbname.ACHVORG; | | truncate TABLE dbname.WORKFLOWNODE; | | truncate TABLE dbname.ZONESERVICE; | | truncate TABLE dbname.ZONESERVICEFILE; | +------------------------------------------------------------+ 7 rows in set mysql> 2. Replace the “|” before and after each truncate statement with a blank character Use a text editor (such as Notepad++) to replace the "|" before and after each truncate statement with a blank character to facilitate copying and executing multiple statements at once. Before replacement: After replacement: 3. Copy the truncate statement to the mysql command line and execute it Copy the truncate statement to the mysql command line for execution. You can copy multiple statements at a time for execution. mysql> truncate TABLE dbname.ZONESERVICE; Query OK, 0 rows affected mysql> This will clear all tables in the database. It's simple~ Comparison between truncate, drop, and delete As mentioned above, truncate is very similar to delete and drop. In fact, there are still significant differences between these three. The following is a brief comparison of the similarities and differences between the three.
This is the end of this article about how to use MySQL truncate command to quickly clear all tables in a database. For more information about MySQL truncate to clear database tables, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implementation of Nginx filtering access logs of static resource files
>>: Vue realizes the function of uploading photos on PC
Seamless carousel is a very common effect, and it...
In development projects, we can monitor SQL with ...
1. When inserting, updating, or removing DOM elem...
Table of contents When developing, analyzing the ...
MySQL is a commonly used open source database sof...
1. Transactions have ACID characteristics Atomici...
Swap memory mainly means that when the physical m...
MySQL stored procedures, yes, look like very rare...
Table of contents Preface Introduction-Official E...
Preface The gradient of the old version of the br...
WeChat applet calculator example, for your refere...
Original source: www.bamagazine.com There are nar...
Preface In the process of developing a mini progr...
When I was writing join table queries before, I a...
Table of contents 1. Basic types 2. Object Type 2...