1. Create a table
create table table_name(
name1 type1,
name2 type2,
name3 type3,
)character set character set collate check rule engine storage engine
Description:
1.name indicates the column name
2.type indicates the type of the column
3.charater set character set, if not specified, the character set of the database where it is located shall prevail.
4.collate validation rules, if not specified, the validation rules of the database where it is located shall prevail.
5. Storage engines include MyISAM and InnoDB.
View the table structure
desc table_name;
among them, Field (attribute name), Type (field type), NuLL (whether it is allowed to be empty), Key (index type), Default (default value), Extra (expansion).
Different storage engines create different files.
When the storage engine is MyISAM, such as table tt1, there are three files (.frm table structure, .MYD table data, .MYI table structure), if InnoDB, there are files (.frm, .ibd)
2. Modify the table
1. Add a field to the table.
alter table tt1 add age int;
alter table tt1 add sex int comment 'image path' after name;
2. Modify field size
alter table tt1 modify name varchar(10);
3. Delete column
alter table tt1 drop sex;
4. Modify table Name
Note that the name of the library cannot be directly modified, only backup first, and then delete.
alter table tt1 rename to tt2;
5. Modify the character set
alter table tt2 charset=gbk;
6. Modify the field name
alter table tt2 change name xingming varchar(20);