可以修改系统变量 auto_increment_increment
查看步长信息
mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
2 rows in set (0.01 sec)
修改步长信息
mysql> SET @@auto_increment_increment=10; //设置步长
Query OK, 0 rows affected (0.00 sec)
mysql> SET @@auto_increment_offset=10000; //设置步长
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 10000 |
+--------------------------+-------+
2 rows in set (0.01 sec)
修改 my.conf
vi /etc/my.cnf
auto_increment_increment=10;
auto_increment_offset =10000;
重启mysql即可
本文介绍如何在MySQL中修改自增字段的步长(auto_increment_increment)和偏移量(auto_increment_offset),通过设置系统变量来实现更灵活的数据增长模式。包括即时修改和持久化配置的方法。
1833

被折叠的 条评论
为什么被折叠?



