mysql数据库---编码格式基本操作

1.查看数据库编码格式

mysql> show variables like 'character_set_database';

 2.查看数据表的编码格式

mysql> show create table <tableName>;

 3.创建数据库时指定数据库的字符集

mysql>create database <databaseName> character set utf8;

4.创建数据表时指定数据表的编码格式

create table tb_books (
    name varchar(128) not null,
    price double not null,
    bookCount int not null,
    author varchar(128) not null ) default charset = utf8;

5.修改数据库的编码格式

mysql>alter database <databaseName> character set utf8;

6.修改数据表格编码格式

mysql>alter table <tableName> character set utf8;

7.修改字段编码格式

mysql>alter table <tableName> change <column_name> <column_name> <type> character set utf8;

mysql>alter table user change username username varchar(128) character set utf8 not null;

 8.添加外键

mysql>alter table tb_product add constraint fk_1 foreign key(factoryid) references tb_factory(factoryid);
mysql>alter table <tableName> add constraint <F_keyName> foreign key<column_name> REFERENCES <F_tableName><column_name>;

9.删除外键

mysql>alter table tb_people drop foreign key fk_1;
mysql>alter table <tableName> drop foreign key <F_keyName>;
posted @ 2018-02-10 04:06  穿格子衫的孔乙彼  阅读(273)  评论(0编辑  收藏  举报