View, create, and modify database and data table encoding formats in MySQL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.