Permanently setting auto_increment_offset in MySQL

跟風遠走 提交于 2019-12-02 07:50:22

As per MySQL documentation you need to set values of auto_increment_offset for both GLOBAL and SESSION.

SET GLOBAL auto_increment_offset  = 2;
SET SESSION auto_increment_offset  = 2;

SHOW VARIABLES LIKE '%auto_increment_offset%';

If the global value of either variable is set, its effects persist until the global value is changed or overridden by setting the session value, or until mysqld is restarted. If the local value is set, the new value affects AUTO_INCREMENT columns for all tables into which new rows are inserted by the current user for the duration of the session, unless the values are changed during that session.

To set it globally you should add prefix 'GLOBAL' or '@@global.'. For example -

SET @@GLOBAL.auto_increment_offset = 2;

The '@@' is the same as 'SESSION' or '@@session.', it sets session variable.

Using System Variables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!