Mysql中设置自增长起始值和递增值
1.查询默认配置 mysql> show variables like 'auto_inc%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | +--------------------------+-------+ 2 rows in set (0.00 sec) auto_increment_increment 是mysql增长的起始值,默认值为1; auto_increment_offset 是mysql的递增值,即每次增长几,默认值为1; 2.修改相关配置 修改增长起始值: mysql> set @@auto_increment_increment=10; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'auto_inc%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 10 | | auto_increment_offset | 1 | +--------------------------+-------+ 2 rows in set (0.00 sec) 修改递增值: mysql> set @@auto_increment_offset=2; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'auto_inc%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 10 | | auto_increment_offset | 2 | +--------------------------+-------+ 2 rows in set (0.00 sec) 注:修改配置整个数据库都会受到影响,不是某个库或表