更改步骤auto_increment字段的增量为 [英] Change the step auto_increment fields increment by

查看:93
本文介绍了更改步骤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解决方案:

Unortodox solutions could that could be considered:

  1. 在同一台计算机上启动两个具有不同端口的MySQL服务器(一个端口使用auto_increment_increment=1,另一个端口使用auto_increment_increment=2)
  2. 使用一些服务器端魔术(PHP,ASP,???)以及关闭表auto_increment进行手动计算(只需简单查看一下id和+ = 2即可)并在INSERT查询中提供id.
  1. Launch two MySQL servers on same machine, with different ports (one with auto_increment_increment=1 other with auto_increment_increment=2)
  2. Use some serverside magic (PHP, ASP ,???) combined with turning off tables auto_increment to manually calculate (simple peek at last id and +=2 would be ok) and provide id in INSERT query.

一些官方MySQL常见问题解答

这篇关于更改步骤auto_increment字段的增量为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆