Differences Between Auto-incrementing primary keys of mysql Storage types and primary keys of mysql Storage

Source: Internet
Author: User

Differences Between Auto-incrementing primary keys of mysql Storage types and primary keys of mysql Storage

Q: if there is a table with an auto-increment primary key whose field is id, after 10 data entries have been inserted into the table, the data with id and 10 has been deleted, restart mysql and insert a data record. What is the id of the data record, which is 8 or 11?
A: If the table type is MyISAM, it is 11. If the table type is InnoDB, the id is 8.
This is because the two types of storage engines store the maximum ID records in different ways, MyISAM table records the maximum ID to the data file, the maximum ID value of the auto-incrementing primary key of mysql is not lost;
While InnoDB records the maximum ID value to the memory. Therefore, after you restart mysql or OPTIMIZE the table, the maximum ID value will be lost.

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.