Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of deleting a large amount of data quickly by mysql

Shulou Source: shulou.com Published: 2022-06-01 02:11:27 09月28日 Update

This article mainly introduces the method of quickly deleting a large number of data by mysql, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The method of mysql to delete a large amount of data: first, create a temporary table with the same structure as the original table; then insert the data that needs to be retained into the temporary table and drop the original table; finally, rename the temporary table to the original table name.

Mysql method to delete a large amount of data:

Option 1.

Use delete directly

Because the execution speed of delete is proportional to the number of indexes, if there are more indexes in the table, it will take hours or even days to use delete.

Option 2.

(1) create a temporary table with the same structure as the original table

(2) insert the data that needs to be retained into the temporary table

(3) original drop table

(4) rename the temporary table to the original table name

After testing, the drop table usually takes less than 3 seconds.

The main time-consuming step of this scheme is the second step. If there is not a large amount of data to be retained, this scheme is the best one.

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the method and content of mysql to delete a large amount of data quickly. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Tags: Data method scheme structure article same index little value content at the same time hour time friend proportional step ribbon industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Shulou Tech Info Shulou Information vpn