How to set auto_increment value in mysql?
by Ramya[ Edit ] 2008-05-29 10:42:55
In mysql, default auto_increment value is 1 and if you want to change/set the auto_increment value then use the following.
mysql> set @@auto_increment_increment = 10;
It will set the default value of auto_increment from 1 to 10.
Likewise you can set value for "auto_increment_offset". Auto_increment_offset refers to the starting value of the auto_increment.Default starting value of auto_increment_offset is 1 and to change the default value use the following,
mysql> set @@auto_increment_offset = 10;
It will set the auto_increment_offset value from 1 to 10.
To view the changed value use the following,
mysql> show variables like 'a%';
it will result,
| Variable_name | Value |
| auto_increment_increment | 10 |
| auto_increment_offset | 10 |
| automatic_sp_privileges | ON |
> Changed value will persist only till you exit mysql.
> If you exit and start mysql again, the value of auto_increment_increment will be 1 by default.
> Again you have to set the AUTO_INCREMENT value.