03_ Chinese garbled processing _01_mysql database character Set knowledge

Source: Internet
Author: User

"MySQL database common character Set Introduction"

In the Internet environment, the character sets commonly used when using MySQL are:

"How to choose the right character set"

1. If you are dealing with a wide variety of text, publish to a different language country region, should choose the Unicode character set, for MySQL is UTF-8 (each Kanji 3 bytes), if the application needs to handle English, only a few Chinese characters use UTF8 better (mixed in Englishand Chinese).

2. If you only need to support Chinese , and the volume of data is large, performance requirements are also high, you can choose GBK (fixed length: Each Chinese character account for double-byte, English also account for double-byte), if you need a large number of operations, such as: comparative sorting, fixed long character set, faster, higher performance.

3. The utf8mb4 character set may be required to handle mobile internet services.

"View the character sets supported by the current MySQL system"

Use "show character set; "To view:

View the current MySQL character set settings

Use "Show variables like ' character_set% '"

|      Variable_name | Value |

|character_set_client| UTF8 |----------Client Character Set

|character_set_connection| UTF8 |----------Connection character Set

|      Character_set_database | UTF8 |----------database character Set, configuration file designation or build table designation

|     Character_set_filesystem | binary |----------

|Character_set_results| UTF8 |----------Returns the result character set

|     Character_set_server | latin1 |---------Server character Set, configuration file designation or database build table designation

|     Character_set_system | Utf8|


"Use Set Names * * * *" to solve garbled problems "

Let's start by creating a "user" table in the test database that MySQL created by default

Then we'll add some data to the user table:

will find that inserting English is normal, but once inserted in Chinese will appear "incorrect string value:" \XD5\XC5\XC8\XFD "for column ' name ' at row 1" error.

Let's take a look at the character encoding of its database test, which is Latin1 encoded by default.

Then look at the character encoding of the table user: the same Latin encoding

If the database and the table are latin1 encoded, how can I insert Chinese data? As follows:

Use "Set names Latin1;" Set the encoding, and then insert the Chinese text field.

Next query, close cmd, re-open a cmd to log in again, for query operation.

Find the query comes out again garbled, we deal with it again,

Take a look at the specific role of "SET names * * * *":

First look at the character set settings by default for database test:

Use "Set names UTF8;" And look at the results:

03_ Chinese garbled processing _01_mysql database character Set knowledge

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.