preface

The essence of Chinese data problem in SQL is character set problem. Computers can only read binary; humans read symbols more. There needs to be a binary to character correspondence (character set)…

Mysql > insert into mysql

  • Mysql operation 01 – Basic instructions, SQL library operations
  • Mysql > select * from ‘SQL’;
  • Mysql operation 03 – SQL data operation
  • Mysql > alter table SQL > alter table SQL > alter table SQL > alter table SQL > alter table SQL
  • Mysql Operations 05 – SQL advanced data operations

Chinese data problems

The nature of Chinese data problem is character set problem.

Computers can only read binary; humans read symbols more. There needs to be a binary to character correspondence (character set);

The client failed to insert Chinese data to the server. Procedure

Insert into my_student values(5,' DDD ',' 99 ',' 99 '); / / an errorCopy the code

The reason:

\xD5\xD5\xD4\xBD represents the hexadecimal conversion of the corresponding binary encoding of “Zhang Yue” under the current encoding (character set) : two Chinese characters = “four bytes” (GBK)

Error:

The server does not recognize the corresponding four bytes: the server thinks the data is UTF8, a Chinese character with three bytes; Read three bytes into Chinese characters (failed), read the remaining three bytes (not enough); It failed.

All database servers assume that some features are stored via server-side variables; The system reads its own variables first to see how they should behave.

See what character sets the server recognizes

Show character set;Copy the code

Basically: the server is versatile and supports any character set.

Since servers recognize so much, there is always a default character set that the server deals with clients

Show variables like 'character_set%';Copy the code

Root cause:

The client data can only be GBK, while the server considers it UTF8. Contradictory output.

Solution:

Change the server to accept the default character set GBK;

GBK set Character_set_client = GBK;Copy the code