Mysql deletes some data from a large table.

Source: Internet
Author: User


Mysql has not written a blog for a long time to delete some data from a large table. The latest project is coming online. I have to stay with my mom after work. There is really no time to update. Someone raised a question today. A table on www.2cto.com has 0.1 billion million data records and an auto-increment ID. The maximum value is 0.1 billion 60 million. If you need to delete data greater than 2.5 million, how can you quickly delete it? At that time, I took a look at the data, So when should I delete the big data? Why is the most terrible lock table swollen? Can't I do it? I don't want to add an index. In mysql, the addition of "low_priorty", "quick", and "ignore" in the delete statement is not helpful. We can see that there is a solution in the mysql document: http://dev.mysql.com/doc/refman/5.0/en/delete.html If you are deleting tables rows from a large table, you may exceed the lock table size for an InnoDB table. to avoid this problem, or simply to minimize the time that the table remains locked, the following strategy (which does not use DELETE at all) might be helpful: select the rows not to be deleted into an empty table that has the same structure as the original table: insert into t_copy SELECT * F ROM t WHERE ...; use rename table to atomically move the original table out of the way and rename the copy to the original name: rename table t TO t_old, t_copy TO t; Drop the original table: drop table t_old; E is not good. Simple translation: innodb will exceed the lock table size limit when multiple rows of data on the standard are deleted, the minimal solution to reduce the lock table time is: 1. Select the data that does not need to be deleted, and rename the original table if they exist in an empty table with the same structure, and name the new table as the original table name. 3. Delete the original table. In summary, you can use the new table to copy data and delete the old table When deleting a part of the data in the large table, rename method.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.