简体   繁体   English

Heroku 和 ClearDB MySQL 自动增量

[英]Heroku and ClearDB MySQL Auto Increment

I am using ClearDB for a mysql database.我将 ClearDB 用于 mysql 数据库。 I have a table with an auto incremented primary key.我有一个带有自动递增主键的表。 The problem is that rather than it incrementing by 1, its incrementing by 10. How can I fix this please?问题是它不是增加1,而是增加10。请问我该如何解决这个问题?

Also when I tested the db on local host, the incrementation was working correctly.此外,当我在本地主机上测试数据库时,增量工作正常。

MySQL has a configuration option for this: auto_increment_increment . MySQL 对此有一个配置选项: auto_increment_increment It's possible for the option to be set to 10 on your ClearDB host, but 1 on your local host.在您的 ClearDB 主机上可以将选项设置为 10,但在本地主机上设置为 1。

Check it in each environment:在每个环境中检查它:

SELECT @@auto_increment_increment;

If it's set to 10 on the ClearDB environment, you'll have to ask whoever set up that environment why it's configured that way.如果在 ClearDB 环境中设置为 10,您将不得不询问设置该环境的人为什么要这样配置。 There might be a good reason.可能有一个很好的理由。

Unfortunately it's a global setting, so if it's set on the server it affects all tables in all databases on that MySQL instance.不幸的是,它是一个全局设置,因此如果在服务器上设置它会影响该 MySQL 实例上所有数据库中的所有表。

You can override the value per session, so if you want your app to use a different value than the global value you can execute this as an SQL query before you do any INSERTs:您可以覆盖每个 session 的值,因此如果您希望您的应用程序使用与全局值不同的值,您可以在执行任何 INSERT 之前将其作为 SQL 查询执行:

SET auto_increment_increment = 1;

But that only takes effect for the current session, so you'd have to do it every time you open a new session.但这仅对当前的 session 生效,因此每次打开新的 session 时都必须这样做。

Also double-check this related option, because it's often set to something non-default if the increment has been changed:还要仔细检查这个相关选项,因为如果增量已更改,它通常会设置为非默认值:

SELECT @@auto_increment_offset;

ClearDB sets the auto_increment value globally to 10 to facilitate the cluster functionality they do. ClearDB 将 auto_increment 值全局设置为 10 以促进它们执行的集群功能。 You cannot override this, Even on single-tenant clusters.您不能覆盖它,即使在单租户集群上也是如此。 this is always in multiples of 10. They will not adjust it for you.这始终是 10 的倍数。他们不会为您调整它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM