引用自 https://www.cnblogs.com/shootercheng/p/5836657.html
1、查看数据库的编码格式
show variables like 'sharacter_set_database';
2、查看数据表的编码格式
show create table <表名>
3、创建数据库时指定数据库的字符集
create database <数据库名> character set utf8;
4.常见数据表时指定数据表的编码格式
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;
5.修改数据库的编码格式
alter database <数据库名> character set utf8;
6、修改数据库的编码
alter table <数据库名> character set utf8;
7、修改字段编码格式
alter table <表名> change <字段名> <字段名> <类型> character set utf8;
8、添加外键
alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid);
alter table table <表名> add constraint <外键名> foreign key <字段名> REFERENCES <外键表名><字段名>;
9、删除外键
alter table tb_people drop foreign key fk_1;
alter table <表名> drop foreign key <外键名>;