Permanently setting auto_increment_offset in MySQL

后端 未结 2 1552
Happy的楠姐
Happy的楠姐 2021-01-28 17:37

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.

2条回答
  •  长情又很酷
    2021-01-28 18:24

    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.

提交回复
热议问题