It is very easy to delete data and tables in MySQL, but you need to be careful because all data will disappear once deleted. Deleting Data To delete data in a table, use the delete keyword. Delete data with specified conditions Delete the user with id 1 in the user table: delete from User where id = 1; Delete all data in the table Delete all data in the table without changing the table structure. For MyISAM, disk space will be released immediately, but InnoDB will not release disk space. delete from User; Free up disk space optimize table User; Delete a table There are two ways to delete a data table:
drop Using the drop keyword will delete the entire table, leaving nothing behind. drop table User; truncate The truncate keyword only deletes the data in the table and retains the table structure. truncate table User; Question for consideration: How to batch delete tables with the same prefix? There is no direct command to implement -- Delete the table starting with "wp_": SELECT CONCAT( 'drop table ', table_name, ';' ) AS statement FROM information_schema.tables WHERE table_schema = 'database_name' AND table_name LIKE 'wp_%'; Here, replace database_name with the name of the database and wp_ with the prefix of the tables that need to be deleted in batches. Note that only the drop command can be used like this: drop table if exists tablename`; truncate can only be used like this: truncate table `tp_trade`.`setids`; Summarize
This is the end of this article about Mysql deleting data and data tables. For more information about Mysql deleting data and data tables, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue3 encapsulates the magnifying glass effect component of Jingdong product details page
>>: Docker meets Intellij IDEA, Java development improves productivity tenfold
Table of contents 1. Original Definition 2. JS op...
Container lifecycle The life cycle of a container...
1. Prerequisites 1. The project has been deployed...
This article example shares the specific code for...
Table of contents Preface Instruction Basics Hook...
1. Basic use <!DOCTYPE html> <html lang=...
environment Hostname ip address Serve Jenkins 192...
1. Download the latest nginx docker image $ docke...
When a company builds Docker automated deployment...
Table of contents Preface Example summary Preface...
MySQL installation (4, 5, 6 can be omitted) State...
1. The div css mouse hand shape is cursor:pointer;...
1. Click the server host and click "Virtual ...
CSS3Please Take a look at this website yourself, ...
Preface var is a way to declare variables in ES5....