First, view the database encoding format
?
| 1 |
mysql> show variables like‘character_set_database‘; |
Second, look at the data table encoding format
?
| 1 |
mysql> show createtable<表名>; |
Iii. specifying the character set of a database when creating a database
?
| 1 |
mysql>createdatabase <数据库名> character setutf8; |
Iv. specifying the encoding format of a data table when creating a data table
?
| 12345 |
create table tb_books ( name varchar(45) not null, price double not null, bookCount int not null, author varchar(45) not null ) default charset = utf8; |
V. Modifying the encoding format of the database
?
| 1 |
mysql>alterdatabase <数据库名> character setutf8; |
Vi. Modifying data table encoding format
?
| 1 |
mysql>altertable <表名> character setutf8; |
Vii. Modifying the field encoding format
?
| 123 |
MYSQL> alter table < table name > Change < Field name > < Field name > < type > character set UTF8; MYSQL> alter Table user change username username varchar () character set utf8 not null |
Eight, add foreign key
?
| 12 |
mysql>alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid);mysql>alter table <表名> add constraint <外键名> foreign key<字段名> REFERENCES <外表表名><字段名>; |
Nine, delete foreign keys
?
| 12 |
mysql>altertable tb_people drop foreign key fk_1;mysql>alter table <表名> drop foreign key<外键名>; |
Summarize
The above is the whole content of this article, I hope that the content of this article on everyone to learn or use MySQL can help, if there are questions you can message exchange, thank you for the script home support.
View, create, and modify database and data table encoding formats in MySQL