mysql> help alter tablename: ' alter table ' description:syntax:alter [online | OFFLINE] [IGNORE] TABLE tbl_name [alter_specification [, alter_specification] ...] [partition_options]alter_specification: table_options | ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name ] | ADD [COLUMN] (col_name Column_definition,...) | add {index| key} [index_name] [index_type] (Index_col_name,...) [index_option] ... | add [constraint [symbol]] primary key [index_type] (Index_col_name,...) [index_option] ... | add [constraiNt [symbol]] unique [index| key] [index_name] [index_type] (Index_col_name,...) [index_option] ... | add fulltext [index| key] [index_name] (Index_col_name,...) [index_option] ... | add spatial [index| key] [index_name] (Index_col_name,...) [index_option] ... | ADD [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (Index_col_name,...) reference_definition | alter [column] col_name {set default literal | drop default} | change [column] old_col_name new_col_name column_definitIon [first| after col_name] | modify [column] col_name column_definition [first | after col_name] | drop [ Column] col_name | drop primary key | drop {index| Key} index_name | drop foreign key fk_symbol | disable KEYS | ENABLE KEYS | RENAME [TO|AS] new_tbl_name | order by col_name [, col_name] ... | convert to character set charset_name [collate collation_name] | [default] character set [=] charset_name [collate [=] collation_name] | discard tablespace | import tablespace | force | add partition (partition_definition) | DROP PARTITION partition_names | truncate partition {partition_names | all} | coalesce partition number | reorganize partition [partition_names INTO (partition_definitions)] | analyze partition {partition_names | ALL} | CHECK PARTITION {partition_names | ALL} | optimize partition {partition_names | all} | rebuild partition { Partition_names | all} | repair partition {partition_names | all } | partition by partitioning_expression | remove partitioningindex_col_name: col_name [(length)] [asc | desc]index_ Type: using {btree | hash}index_option: key_block_size [=] value | index_type | WITH PARSER parser_name | COMMENT ' String ' table_options: table_option [[,] table_option] ... ( see create table options) partition_options: (See CREATE TABLE options)
For example, use mydb data to add sex, age, and QQ columns to the student table
mysql> use mydbdatabase changedmysql> alter table student add ' Sex ' varchar (1), add ' Age ' tinyint (3) unsigned, add ' QQ ' int (Ten) unsigned;mysql> desc student;+-------+---------------------+------+-----+---------+-------------- --+| field | type | Null | Key | Default | Extra |+-------+---------------------+------+-----+---------+----------------+| id | int (one) | no | pri | null | auto_ increment | | name | varchar ( | no &) nbsp; | mul | null | | | score | int (1) | yes | | 0 | | | sex | varchar (1) | YES | | NULL | | | age | tinyint (3) unsigned | YES | | NULL | | | qq | int (Ten) unsigned | yes | | NULL | |+-------+---------------------+------+-----+---------+ + ---------------+6 rows in set (0.04 SEC)
About adding more than one column at a time, see MySQL official help is not written clearly, in front of each new column need to use the keyword add, and MySQL is no number field type, to use non-negative type, you need to add the unsigned keyword after shaping.
Linux Learning notes: MySQL Modify table structure