Detailed explanation of mysql database Chinese garbled issues, detailed explanation of mysql

Source: Internet
Author: User

Detailed explanation of mysql database Chinese garbled issues, detailed explanation of mysql

When a piece of data with Chinese characters is inserted into the MySQL databaseInsert into employee values (null, 'zhang san', 'female ', '2017-10-08', '2017-11-12 ', 'sales', 1995,' is a good employee! '); When garbled characters appear, you can use the statementshow variables like 'character%'To view the shard set of the current database.

We can see that MySQL uses character sets in six ways: client, connection, database, results, server, and system. It is related to the server: database, server, system (which can never be modified, or UTF-8); it is related to the client: connection, client, and results.

 

Client The character set used by the client.
Connection Set the type of character set used to connect to the database. If the program does not specify the character set type used to connect to the database, it is set according to the default character set on the server.
Database Set the character set used by a database in the database server. If it is not specified during database creation, the character set specified during Server installation will be used.
Results Set the character set used by the database to return data to the client. If not specified, use the default Character Set of the server.
Server Set the default character set specified during Server installation.
System Set the character set used by the database system.

Understand the above information we analyze the cause of garbled characters, the problem lies in the current CMD client window, because the current CMD client input using GBK encoding, and the database encoding format for UTF-8, inconsistent encoding causes garbled characters. However, the encoding format of the current CMD client cannot be modified. Therefore, you can only modify the encoding set of connection, client, and results to inform the server that the currently inserted data adopts GBK encoding, while the server database uses UTF-8 encoding, it can identify the GBK encoding data of the Notification Server and automatically convert it to the UTF-8 for storage. You can use the following statement to quickly set the consumer set related to the client:

  • Sorted set names gbk;

After setting, you can solve the problem of data insertion or garbled data on the client. However, we will immediately find that this setting is only valid in the current window, when the window is closed and the CMD client is re-opened, garbled characters may occur. How can we make a permanent setting? There is a my. ini configuration file under the MySQL installation directory. By modifying this configuration file, you can solve the garbled problem once and for all. In this configuration file, [mysql] is related to client configuration, and [mysqld] is related to server configuration. The default configuration is as follows:

  • Using [mysql]
  • Optional default-character-set = utf8
  • Commit [mysqld]
  • Export character-set-server = utf8

In this case, you only need to change the default encoding default-character-set = utf8 to default-character-set = gbk and restart the MySQL service.

Summary

The above section describes the mysql database Chinese Garbled text. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.