Mysql's character Set operation command Summary _mysql

Source: Internet
Author: User

All of the following runs through the MySQL 5.5 command line:

To view MySQL-supported character sets:

Copy Code code as follows:
Show CharSet;

View Character Set:
Copy Code code as follows:
Status

The following are more specific:
Copy Code code as follows:
Show VARIABLES like ' character_set_% ';

To see how to sort:
Copy Code code as follows:
Show VARIABLES like ' collation_% ';

The default character set is typically used when the database is established, unless specified at the time of establishment:
Copy Code code as follows:
CREATE DATABASE [db-name] CHARACTER SET UTF8 COLLATE utf8_general_ci;

Specify the character set when setting up table:
Copy Code code as follows:
CREATE TABLE [table-name] (id int not null) default CharSet UTF8;

To view the character set used by the database:
Method 1: Locate the directory where the database is stored, enter the directory of the corresponding databases, and view the db.opt file.
Method 2:
Copy Code code as follows:
Show CREATE DATABASE [Db-name];

To view the character set of a table:
Copy Code code as follows:
Show CREATE TABLE [Table-name];

To view the character sets for each table in the database:
Copy Code code as follows:
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 the table.
You can also specify a table:
Copy Code code as follows:
Show table status from [Db-name] like '%filter% ';

To view the character sets for each column in the table:
Copy Code code as follows:
Show full columns from [Table-name];

Or
Copy Code code as follows:
Show table status from [Db-name];

To modify the database character set:
Copy Code code as follows:
ALTER DATABASE [db-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];

To modify the character set of tables and columns (fields):
Copy Code code as follows:
ALTER TABLE [Table-name] CONVERT to CHARACTER SET [Character-name] COLLATE [collation-name];

Just modify the character set of the table:
Copy Code code as follows:
ALTER TABLE [table-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];

Other: You can modify MySQL's default character set for your own needs of the character set, such as Utf-8, when the table's character set defaults to use the database's character set. However, personally feel that the better way is to set up the database when the database to use the character set, we write the program, do not ignore this query:
Copy Code code as follows:
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.