您的位置:首页 > 数据库 > MySQL

Mysql中设置自增长起始值和递增值

2016-01-18 14:22 543 查看
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)

注:修改配置整个数据库都会受到影响,不是某个库或表
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: