Globalization and localization of MySQL: Character sets, proofing sets, Chinese coding issues

Source: Internet
Author: User

The content of this article:

    • What is a character set? What is a proofing set?
    • Viewing character sets and proofing sets
    • Set up character sets and proofing sets
    • Problems with Chinese data in MySQL

Starting Date: 2018-04-19

What is a character set? What is a proofing set?

    • A character set is a collection of letters and symbols, and each character encoding is determined by a character set.
    • The proofing set is the standard for proofreading letters and symbols. Proofing sets affect the sorting and searching of characters.

To view character sets and proofing sets:

    • View MySQL-supported character sets: show character set;
    • View MySQL-supported proofing sets: Show collation;
    • View the default character set on the server: show variables like ' char% ';
    • View the default character set on the server: show variables like ' collation% ';

The meaning of the default character set on the service side:

The meaning of the default proofing set for the service side:

Set up character sets and proofing sets

Set the character set of the database data table:
    • In fact, a character set is rarely a server-wide (or even database-scoped) setting. Different tables, and even different columns, may require different character sets, and both can specify "MySQL must know" when creating a table. The following describes the creation of databases, data tables without using the default configuration
      • Creating database: Create Database name CharSet Character Set collate proofing set; "Proofing sets are not necessary, each character set has a default proofing set, and if no proofing set will use the default"
      • Create data table: the CREATE TABLE table name CharSet character Set collate proofing set;
      • Specify a character set and a proofing set for a column:

Set the server and client character sets:
    • Syntax: Set character_set_xxx = Character set; "Character_set_xxx is the default character set for the service side of the view set above, meaning it has been labeled" "This setting is session-level only when the secondary connection takes effect. 】
    • If you want to permanently modify the character set on the server side: Modify the My.ini file under Windows "is the MySQL configuration file, you can view it from the MySQL service," in mysqld, modify the value of Character-set-server to the specified character set " Modify the character set on the server side "

Add:
    • Cannot permanently configure the client's character set, which is considered by the server side, each client's character set is indeterminate and should be set by the client to specify the character set for the secondary connection.

Problems with Chinese data in MySQL:

    • The Chinese data problem in MySQL is essentially a character set problem, and to identify and store Chinese data, you must set up a character set that can encode Chinese.
    • Both GBK and UTF8 support MySQL, and it is common to change the MySQL character set to UTF8 to recognize Chinese.
    • How to configure (take GBK as an example):
      • One of the first things to consider is: If you use the command line mode, by default the character encoding format is GBK, that is, the client's data encoding is GBK;
      • If the server to identify the client came from the Chinese, then you need to set the server to think that the client's character set is gbk;set character_set_client = ' GBK ';
      • If the server wants to return Chinese to the client, the character set of the data returned to the client by the server needs to be gbk;set character_set_results = ' GBK ';
      • For a single session, you can directly use set names = ' GBK '; "Execute set names= ' GBK ' is the character_set_client, Character_set_connection, character_set_ Results These 3 parameter values are set to GBK "

Globalization and localization of MySQL: Character sets, proofing sets, Chinese coding issues

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.