The table structure is as follows:
Mysql>Show create table person;| Person |Create Table 'person '('number'Int(11) Default null, 'name' varchar (255) Default null, 'birthday'DateDefault null) Engine= MyISAM default charset = utf8 |
Delete column:
Alter table person drop column birthday;
Add column:
Alter table person add column birthday datetime;
Modify the column number to bigint:
Alter table person modify number bigint not null;
Or change the number to ID and the type is bigint:
Alter table person change numberIDBigint;
Add primary key:
Alter table person add primary key (ID);
Delete primary key:
Alter table person drop primary key;
Add a unique index:
Alter table person add unique name_unique_index ('name ');
A unique index is created for the name column. The index name is name_unique_index.
Add a common index:
Alter table person add index birthday_index ('birthday ');
Delete An index:
Alter table person drop index birthday_index; alter table person drop index name_unique_index;
Disable non-unique Indexes
Alter table person disable keys;
Alter table... disable keys: Stop MySQL from updating non-unique indexes in the MyISAM table.
Activate a non-unique index
Alter table person enable keys;
Alter table... enable keys to recreate the lost index.
Set the default character set and all character columns of the table (Char, varchar, text) To the new character set:
Alter table person convert to Character Set utf8;
Modifies the encoding of a column in a table.
Alter table person change name varchar (255) Character Set utf8;
Only change the default character set of a table
Alter table person default Character Set utf8;
Modify Table Name
Rename table person to person_other;
Move a table to another database
Rename table current_db.tbl_name to other_db.tbl_name;