为什么auto_increment id不能一一增加,如何设置? [英] Why the auto_increment id does not increase one by one, how to set it?

查看:322
本文介绍了为什么auto_increment id不能一一增加,如何设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MariaDB Galera群集(3个节点),我将uid设置为自动增加,并成为表的主键为

I have a MariaDB Galera Cluster(3 nodes), I set uid to increase automatically and be the primary key of the table as

 `uid       | int(11)     | NO   | PRI | NULL    | auto_increment`. 


 MariaDB [hello_cluster]> select uid from table order by uid limit 10;
    +-----+
    | uid |
    +-----+
    |   3 |
    |   6 |
    |   9 |
    |  12 |
    |  15 |
    |  18 |
    |  21 |
    |  24 |
    |  27 |
    |  30 |
    +-----+

我尝试了以下命令,但它不起作用

I tried the following command, and it does not work

 alter table uid AUTO_INCREMENT=1

推荐答案

这是设计使然,在

不要依赖自动递增的值是连续的. Galera使用基于自动增量的机制来生成唯一的无冲突序列,因此在每个单个节点上该序列都会有缺口.

使用多主机管理自动增量 ,这也是为什么观察到的自动增量与簇数相同的步长的原因.

The rational is explained in Managing Auto Increments with Multi Masters, and is also why the observed auto-increment has the same step as the number of clusters.

MySQL具有系统变量auto_increment_increment和auto_increment_offset,用于管理多主环境中的自动增量序列".使用这些变量,可以建立多主复制,其中每个主节点中的自动增量序列交织,并且群集中不应发生任何冲突.不管哪个主控获得了INSERT.

MySQL has system variables auto_increment_increment and auto_increment_offset for managing auto increment 'sequences' in multi master environment. Using these variables, it is possible to set up a multi master replication, where auto increment sequences in each master node interleave, and no conflicts should happen in the cluster. No matter which master(s) get the INSERTs.

即使没有集群,由于事务回滚和删除的记录,依靠自动增量列作为密集序列也很少是好"主意.

Even without clusters, it is rarely a "good" idea to rely on auto-increment columns to be dense sequences due to transaction rollbacks and deleted records.

这篇关于为什么auto_increment id不能一一增加,如何设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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