MySQL Auto_increment 2 x 2

Ber*_*ira 8 mysql auto-increment

前几天我安装了 MySQL Workbench,访问了我公司的数据库,并为自己制作了一张表。到现在为止还挺好。问题是,我注意到我的auto_increment以 2 递增 2。例如:

ID    NAME
1     Paul
3     Jack
5     Louis
7     John
...
Run Code Online (Sandbox Code Playgroud)

当我这样做时SHOW VARIABLES LIKE 'auto_inc%'

'auto_increment_increment', '2'
'auto_increment_offset', '1'
Run Code Online (Sandbox Code Playgroud)

所以我尝试设置auto_increment_increment为 1 :

SET @@auto_increment_increment=1
Run Code Online (Sandbox Code Playgroud)

再次验证后,SHOW VARIABLES LIKE 'auto_inc%'我确认它“有效”的结果是:

'auto_increment_increment', '1'
'auto_increment_offset', '1'
Run Code Online (Sandbox Code Playgroud)

但是我的 ID仍然2为单位递增2

我第一次这样做时,它运行良好,然后我关闭了 MySQL Workbench,发现当我再次打开它时,它再次auto_increment_increment设置为2。现在我想再做一次,但它似乎不再起作用了。

任何人都可以帮我解决这个问题吗?

谢谢你们。

Mor*_*ker 7

使用的前缀:

SET @@auto_increment_increment=1;
Run Code Online (Sandbox Code Playgroud)

是相同的:

SET @@SESSION.auto_increment_increment=1;
Run Code Online (Sandbox Code Playgroud)

修改此设置时,它仅与您当前的会话相关。

要进行更永久的修复,请尝试:

SET GLOBAL auto_increment_increment=1;
Run Code Online (Sandbox Code Playgroud)

是相同的:

SET @@GLOBAL.auto_increment_increment=1;
Run Code Online (Sandbox Code Playgroud)