search

Home  >  Q&A  >  body text

如何修改mysql主键自动增长的起始值

自增长跟PHP索引数组的下标一样,会根据当前最大的那个值加1。

为什么系统能够从1开始进行自动增长?而为什么每次又是自动增加1?
系统是通过系统里面的配置文件来识别。
show variables like ‘auto_increment%’;

那么我如何修改这两项呢?????

怪我咯怪我咯2786 days ago681

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:39:47

    CREATE TABLE `xxx` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`id`)
    )AUTO_INCREMENT=4;

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:39:47

    It is not recommended to modify the system settings. If you need to modify the auto-increment starting value of a certain table, you can use:

    alter table table_name auto_increment = 9999;

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:39:47

    As Ewellyuan said, it is best not to modify system properties, but only modify table properties. If you really want to change it, you can modify it through the following command:
    mysql> set [global] auto_increment_increment=X;
    where global refers to the global modification. Without global, it is just the session level (for the current user connection, if you exit The modification will be invalid)

    reply
    0
  • Cancelreply