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
Upgrade background: In order to solve the vulnera...
1. at is configured to write "This is a at t...
This article example shares the specific code of ...
HTML+CSS+JS imitates win10 brightness adjustment ...
Table of contents The essence of QR code login Un...
This article describes how to boot the Linux syst...
1. Install MySQL database ① Download and unzip an...
Official website explanation: When a component is...
This article example shares the specific code of ...
question Nginx takes $remote_addr as the real IP ...
Before the arrow was shot, the bow whispered to t...
environment: MAC_OS 10.12 Python 3.6 mysql 5.7.25...
The props of the component (props is an object) F...
Preface: When we are making web pages, we often n...
Installation environment: CentOS7 64-bit MINI ver...