Search code examples
phpmysqlmysql-workbenchmysql-error-1064

How to set auto_increment_offset and auto_increment_increment for a single database


Is it possible to set auto_increment_offset and auto_increment_increment variables only for a single database without affecting any other database?

The reason why I want this is I am implementing a master master replication on a database but I have a cloud VPS with 30 domains and its databases. So I need to set this variables for a single database without affecting the other databases.


Solution

  • No, it is a global variable. You can set it per session though, so the PHP software could be written to set it each time the database connection is opened.

    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.