MySQL character set operation command summary _ MySQL

Source: Internet
Author: User
The following is a summary of MySQL character set operation commands that are run in mysql 5.5 command line:

View the character sets supported by MySQL:
Show charset;
View character set:
Status
The following is more specific:
Show variables like 'character _ set _ % ';
View the sorting method:
Show variables like 'collation _ % ';
The default character set is generally used when the database is created, unless it is specified at the time of creation:
Create database [db-name] character set utf8 COLLATE utf8_general_ci;
Specify the character set when creating a table:
Create table [table-name] (id int not null) default charset utf8;
View the character set used by the database:
Method 1: Find the directory where the database is stored, enter the Directory of the corresponding database, and view the database. opt file.
Method 2:
Show create database [db-name];
View the character set of the table:
Show create table [table-name];
View the character set of each table in the database:
Show table status from [db-name];
If the character set is not described after each column, the character set of the column is the same as that of the table.
You can also specify a table:
Show table status from [db-name] like '% filter % ';
View the character set of each column in the table:
Show full columns from [table-name];
Or
Show table status from [db-name];
Modify the database character set:
Alter database [db-name] default character set [character-name] COLLATE [collation-name];
Modify the character set of tables and columns (fields:
Alter table [table-name] convert to character set [character-name] COLLATE [collation-name];
Only modify the character set of the table:
Alter table [table-name] default character set [character-name] COLLATE [collation-name];
Others: you can modify the default character set of mysql to the desired character set, such as UTF-8. when creating a table, the character set of the table uses the character set of the database by default. However, I personally think the better way is to set up the character set used by the database when creating the database. we should not ignore this query when writing the program:
Set names 'utf8 ';

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.