MySQL 修改表中的字段,使其自增

例如,我想使字段 id 自增。

1、查看表定义

mysql> DESC user;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | int(8)      | NO   | PRI | NULL    |       |
| account  | varchar(16) | YES  |     | NULL    |       |
| password | varchar(16) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

2、更改表结构

mysql> ALTER TABLE user CHANGE COLUMN id id INT(8) NOT NULL AUTO_INCREMENT;

3、重新查看表定义

mysql> DESC user;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| id       | int(8)      | NO   | PRI | NULL    | auto_increment |
| account  | varchar(16) | YES  |     | NULL    |                |
| password | varchar(16) | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
原文地址:https://www.cnblogs.com/Satu/p/10652044.html