Change the step auto_increment fields increment by(更改步骤 auto_increment 字段增量)
问题描述
如何将 MySQL 增量中的 auto_increment 字段的数量从默认值 (1) 更改为 n?
How do I change the amount auto_increment fields in MySQL increment by from the default (1) to n?
推荐答案
如果您想将自动增量步长从 1 更改为 N 那么有一个解决方案.它可以在 MySQL 服务器端完成:寻找--auto-increment-increment"启动选项或使用以下命令SET @@auto_increment_increment=2;,但请注意这是服务器范围的更改(所有表都将增加 2).
If you want to change autoincrement step from 1 to N then there is a solution.
It could be done on MySQL server side:
look for '--auto-increment-increment' startup option or use following command SET @@auto_increment_increment=2;, but be warned that this is a server wide change (all tables will increment by 2).
可以考虑的非传统解决方案:
Unortodox solutions could that could be considered:
- 在同一台机器上启动两个 MySQL 服务器,使用不同的端口(一个使用
auto_increment_increment=1另一个使用auto_increment_increment=2) - 使用一些服务器端魔法(PHP、ASP、???)结合关闭表
auto_increment来手动计算(简单地查看最后一个 id 和 +=2 就可以了)并在INSERT查询.
- Launch two MySQL servers on same machine, with different ports (one with
auto_increment_increment=1other withauto_increment_increment=2) - Use some serverside magic (PHP, ASP ,???) combined with turning off tables
auto_incrementto manually calculate (simple peek at last id and +=2 would be ok) and provide id inINSERTquery.
一些官方 MySQL 常见问题
这篇关于更改步骤 auto_increment 字段增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改步骤 auto_increment 字段增量
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
