Permanently setting auto_increment_offset in MySQL

给你一囗甜甜゛ 提交于 2019-12-04 06:44:16

问题


I ran the command as root:

set @@auto_increment_offset = 2;

But the effect cannot be seen from other connections. Why not? It is global.

From http://dev.mysql.com/doc/refman/5.1/en/replication-options-master.html: "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."

That doesn't seem to agree with what I am seeing.

Ultimately, I would like to know if there any way to permanently set the offset for all clients without restarting mysqld?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12033017/permanently-setting-auto-increment-offset-in-mysql

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