语句实例:修改列user_status
mysql> desc users;+-------------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------------+---------------------+------+-----+---------+----------------+| user_id | int(11) unsigned | NO | PRI | NULL | auto_increment || user_name | char(125) | NO | | NULL | || user_pass | char(32) | NO | | NULL | || user_status | enum('0','1') | NO | | NULL | || user_type | tinyint(2) unsigned | NO | MUL | 0 | |+-------------+---------------------+------+-----+---------+----------------+mysql>create table users_tmp like users;mysql>alter table users_tmp modify column user_status enum ('0','1','2') default '2';mysql>desc users_tmp;+-------------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------------+---------------------+------+-----+---------+----------------+| user_id | int(11) unsigned | NO | PRI | NULL | auto_increment || user_name | char(125) | NO | | NULL | || user_pass | char(32) | NO | | NULL | || user_status | enum('0','1','2') | YES | | 2 | || user_type | tinyint(2) unsigned | NO | MUL | 0 | |+-------------+---------------------+------+-----+---------+----------------+mysql>flush tables with read lock;
#-----------------------------------这里是shell命令进入mysql的datadir目录交换.frm文件[root@localhost /var/lib/mysql/test/] cp -a users.frm users.frm.backup[root@localhost /var/lib/mysql/test/] mv users_tmp.frm users.frm #这个会直接删除删除新建的表user_tmp#-----------------------------------
mysql>unlock tables;mysql>desc users;+-------------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------------+---------------------+------+-----+---------+----------------+| user_id | int(11) unsigned | NO | PRI | NULL | auto_increment || user_name | char(125) | NO | | NULL | || user_pass | char(32) | NO | | NULL | || user_status | enum('0','1','2') | YES | | 2 | || user_type | tinyint(2) unsigned | NO | MUL | 0 | |+-------------+---------------------+------+-----+---------+----------------+