How to set id to auto-increment in Mysql

(1) Set auto-increment

  • Option One:
CREATE TABLE IF NOT EXISTS `user`(
   `id` INT UNSIGNED AUTO_INCREMENT,
   `name` VARCHAR(100) NOT NULL,
   `sex` VARCHAR(40) NOT NULL,
   `age` INT(11),
   PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
  • Option II:
alter table user modify id int auto_increment;

(2) Set the auto-increment starting value

show variables like 'auto_increment%';

Insert image description here

set auto_increment_offset=10;
show variables like 'auto_increment%';

Insert image description here

(3) Set the auto-increment interval

set auto_increment_increment=10;
show variables like 'auto_increment%';

Insert image description here
Note:
How to modify the table name?

alter table old_table rename to new_table;

Guess you like

Origin blog.csdn.net/weixin_43166227/article/details/109534902