Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to reset mysql's auto-add bar
How to reset mysql's auto-add bar
There are several ways to reset mysql's auto-add columns:

Method 1: delete from TB 1;

ALTER TABLE TBL AUTO _ INCREMENT = 100;

Note: If there are many tables and data, the speed will be very slow, for example, more than 900,000, and it will take 10 more minutes.

Method 2: Truncate TB1;

To reset mysql's self-added columns, you need to perform the following steps:

1. Support setting the value of self-added column;

ALTER TABLE TABLE _ name AUTO _ INCREMENT = 1;

This method can only set a value greater than the currently used value, but not less than or equal to the value of the currently used self-added column. Myisam If the setting is less than or equal to, the value of the self-added column will be automatically set to:

The current maximum plus 1 will not change innodb.

2. TRUNCATE sets the self-added column to 0. Starting from MySQL 5.0. 13, TRUNCATE resets the self-added column to 0.myisam is the same as innode.

TRUNCATE TABLE table _ name

3. Reset the self-added column to 0 through 3.drop and create methods to regenerate the table.

DROP TABLE table _ name

Create table table_name {...};

The advantages of resetting mysql's automatically added columns in two ways are:

Method 1: you can set AUTO_INCREMENT to any value to start;

Method 2: simple, AUTO_INCREMENT value starts counting again;

Note: Using the above method will delete the existing data.