MySQL Code test

Source: Internet
Author: User
Tags mysql code

Insert into T1 (v1) VALUES (' CN China ');
SELECT * from T1;

1, input GBK, interactive latin1, database latin1
Insert, the client to GBK input as latin1 to explain, to the service, service does not need to transcode, GBK as latin1 into the database, display garbled.
Select, the service does not transcode, returns to the client, the client latin1 as GBK explanation, the display is correct.
2, input GBK, interactive latin1, database GBK
Insert Error: Error 1366 (HY000): Incorrect string value: ' \XD6\XD0\XB9\XFA ' for column ' V1 ' at row 1
The reason is: the client to GBK input as latin1 to explain, to service, service transcoding, latin1 into GBK, error.
3, input GBK, interactive latin1, database UTF8
As with 1, this is because UTF8 English characters are one byte, multibyte character is three bytes.
4, input GBK, interactive GBK, database latin1
Insert Error: Error 1366 (HY000): Incorrect string value: ' \XD6\XD0\XB9\XFA ' for column ' V1 ' at row 1
The reason is: the client to GBK input as GBK to explain, to the service, service GBK into latin1, conversion failure.
5, input GBK, interactive GBK, database GBK
Insert, the client to GBK input as GBK to explain, to the service, service does not need to transcode, directly into the database, stored in the database normal.
Select, the service does not transcode, returns to the client, the client GBK as GBK explanation, the display is correct.
6, input GBK, interactive GBK, database UTF8
Insert, the client to GBK input as GBK to explain, to the service, the service GBK into UTF8, into the database, stored in the database normal.
Select, the service turns UTF8 into GBK, returns to the client, the client GBK as GBK explanation, the display is correct.
7, input GBK, interactive UTF8, database latin1
Insert Error: Error 1366 (HY000): Incorrect string value: ' \XD6\XD0\XB9\XFA ' for column ' V1 ' at row 1
The reason: The client interprets the GBK input as UTF8 to explain the error.
8, input GBK, interactive UTF8, database GBK
Same 7
9, input GBK, interactive UTF8, database UTF8
Same 7

Consider the following situation, input GBK, interactive GBK, database GBK, insert a record, query back normal. What's wrong with changing the interaction to UTF8 now?
Mysql> select * from T1;
+--------+
| V1 |
+--------+
| CN China |
+--------+
1 row in Set (0.00 sec)

mysql> set names UTF8;
Query OK, 0 rows Affected (0.00 sec)

Mysql> select * from T1;
+----------+
| V1 |
+----------+
| CN Juan Ricoh |
+----------+
1 row in Set (0.00 sec)

This is because the UTF8 China, as GBK interpretation, is to show the trickle Ricoh, that is, their corresponding ID is the same. In turn, the same, the GBK Juan Ricoh as UTF8 interpretation, is China, as follows:
mysql> INSERT INTO T1 (v1) VALUES (' CN Juan Ricoh ');
Query OK, 1 row affected (0.08 sec)

Mysql> select * from T1;
+----------+
| V1 |
+----------+
| CN Juan Ricoh |
| CN Juan Ricoh |
+----------+
2 rows in Set (0.00 sec)

mysql> set names GBK;
Query OK, 0 rows Affected (0.00 sec)

Mysql> select * from T1;
+--------+
| V1 |
+--------+
| CN China |
| CN China |
+--------+
2 rows in Set (0.00 sec)

MySQL Code test

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.