MySQL database---Encoding format basic operation

Source: Internet
Author: User

1. View the database encoding format
Mysql> Show variables like ' character_set_database ';
2. View the encoding format of the data table
Mysql> Show CREATE TABLE <tableName>;
3. Specify the character set of the database when creating the database
Mysql>create database <databaseName> character set UTF8;
4. Specify the encoding format of the data table when creating the data table
CREATE TABLE Tb_books (name varchar) is not NULL, the price double is not    null, Bookcount int is not    null,    author varchar (+) NOT null) default CharSet = UTF8;
5. Modify the encoding format of the database
Mysql>alter database <databaseName> character set UTF8;
6. Modify the data table encoding format
Mysql>alter table <tableName> character set UTF8;
7. Modify the field encoding format
Mysql>alter table <tableName> Change <column_name> <column_name> <type> character set UTF8; Mysql>alter Table User change username username varchar (n) character set UTF8 not null;
8. Add a FOREIGN key
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. Delete foreign keys
Mysql>alter table tb_people drop foreign key fk_1;mysql>alter table <tableName> drop foreign key <f_keyname >;

MySQL database---Encoding format basic operation

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.