The view, creation and modification of database and Datasheet coding format in Mysql _mysql

Source: Internet
Author: User
Tags character set

First, view the database encoding format

Mysql> Show variables like ' character_set_database ';

Second, view the data table encoding format

Mysql> Show CREATE table < table name >;

Specifying the character set of a database when creating a database

Mysql>create DB < database name > character set UTF8;

The encoding format of the specified datasheet when you create the datasheet

CREATE TABLE Tb_books (
 name varchar) NOT NULL, price
 double not NULL,
 Bookcount int is not NULL,
 author V Archar () NOT null) default CharSet = UTF8;

V. Modify the encoding format of the database

Mysql>alter DB < database name > character set UTF8;

Six, modify the data table encoding format

Mysql>alter Table < name > character set UTF8;

Modify the field encoding format

Mysql>alter table < table name > change < Field name > < Field name > < type > Character set UTF8;

Mysql>alter Table User change username username varchar (a) character set UTF8 not null;

Eight, add foreign key

Mysql>alter table tb_product Add constraint fk_1 foreign key (Factoryid) references tb_factory (Factoryid);
Mysql>alter table < table name > Add constraint < foreign key name > Foreign key< Field name > REFERENCES < external table name >< field name >;

Ix. Delete foreign keys

Mysql>alter table tb_people drop foreign key fk_1;
Mysql>alter table < table name > drop FOREIGN Key < foreign key name >;

Summarize

The above is the entire content of this article, I hope this article's content for everyone to learn or use MySQL can help, if there is doubt you can message exchange, thank you for the cloud Habitat Community support.

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.