问题
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