Search code examples
mysqldatabaseauto-increment

How to change autoincrement offset and step value for only a single table?


I have a monolithic database which has a table with around 60 million rows. The setup is master-master replicated and one of the masters writes to even autoincrement ids and other master writes to odd autoincrement ids.

But I want to change the setup so that I can use a step size of 4 and offsets 1 and 3 for a single table (the table in question) in the entire database. Is it even possible?


Solution

  • No.

    The MySQL documentation clearly states that the autoincrement offsets are a per MySQL instance settings and will be applied to all tables on a database.

    The documentation can be seen at https://dev.mysql.com/doc/refman/8.0/en/replication-options-master.html#sysvar_auto_increment_increment.

    It is not possible to restrict the effects of these two variables to a single table; these variables control the behavior of all AUTO_INCREMENT columns in all tables on the MySQL server. 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.