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
Suppose Taobao encourages people to shop during D...
describe Returns the time interval between two da...
1. Trash or Classic? Web technology updates very ...
Table of contents 1. Timestamp to date 2. Convert...
W3C, an organization founded in 1994, aims to unl...
This article shares the manual installation tutor...
Table of contents 1. Download MySQL 1.1 Download ...
Transaction isolation level settings set global t...
1. HTML part <Col span="2">Upload...
Using win docker-desktop, I want to connect to co...
Table of contents One-way data flow explanation V...
Table of contents Getting Started with MySQL MySQ...
Table of contents umask Umask usage principle 1. ...
Let me first introduce an interesting property - ...
Preface Everyone knows that many sites now charge...