How to set auto_increment value in mysql?

by Ramya 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_nameValue
auto_increment_increment10
auto_increment_offset10
automatic_sp_privilegesON

> 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.

Tagged in:

763
like
0
dislike
0
mail
flag

You must LOGIN to add comments