How to reset Mysql's self-add column auto_increment the initial value _mysql

Source: Internet
Author: User
Reset MySQL Self-add auto_increment initial value
Note that existing data is deleted by using any of the following methods.

Method One:
Delete from tb1;
ALTER TABLE tbl auto_increment = 100;
(Benefits, you can set auto_increment to start with any value)
Tip: If there are a lot of table columns and data, the speed will be very slow, such as 90多万条, will be more than 10 minutes.

Method Two:
Truncate TB1;
(benefit, simple, auto_increment value to start counting again.)

How to reset MySQL's self-add column

1. Supports setting values for self-added columns

ALTER TABLE table_name auto_increment = 1;
This way, however, you can set a value that is greater than the value you are currently using, and you cannot set values that are less than or equal to the currently used self-added column. MyISAM if the setting is less than or equal, the value of the self-added column is automatically set to
The current maximum value plus 1. The InnoDB will not change.

2. By truncate to set the self-add column to 0, from the MySQL 5.0.13 start truncate can reset the self-add list 0.myisam and Innode are the same.

TRUNCATE TABLE table_name;
3.drop and create rebuild table mode reset self-add column 0

DROP TABLE table_name;
CREATE TABLE table_name {...};
Related Article

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.