Mysql client data garbled, mysql client garbled

Source: Internet
Author: User

Mysql client data garbled, mysql client garbled

Garbled characters appear when inserting Chinese data into mysql:

Mysql> select * from test;
+ ------ + ----------- +
| Id | name |
+ ------ + ----------- +
| 1 | why does one fail? |
| 2 | too many threads? |
| 3 | why does one fail? |
| 4 | too many threads? |
| 5 | too many records |
| 6 | too many threads? |
| 1 | demo1 |
| 2 | demo2 |
| 3 | demo3 |
+ ------ + ----------- +

However, real data can be normally stored in applications.

1. Li Xiaofeng
2 Wang Xiaofeng
3 Xiao Xue
4 Wang Xuefeng
5. luyun
6 peach blossom girls
1demo1
2demo2
3demo3

To display Chinese characters normally on the client, you can modify the sequence set as follows:

Enter show variables like 'Char % ';

Mysql> show variables like 'Char % ';
+ -------------------------- + ------------------------------- +
| Variable_name | Value |
+ -------------------------- + ------------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | gbk |
| Character_set_database | gbk |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | gbk |
| Character_set_system | utf8 |
| Character_sets_dir | D: \ mysql6.0 \ share \ charsets \ |
+ -------------------------- + ------------------------------- +
8 rows in set (0.00 sec)

We can see that character_set_client and character_set_results are both UTF-8 encoded, and now they are all modified to gbk

Mysql> set character_set_client = gbk;
Query OK, 0 rows affected (0.00 sec)


Mysql> set character_set_results = gbk;
Query OK, 0 rows affected (0.00 sec)

Use show variables like 'Char % '; to query

Mysql> show variables like 'Char % ';
+ -------------------------- + ------------------------------- +
| Variable_name | Value |
+ -------------------------- + ------------------------------- +
| Character_set_client | gbk |
| Character_set_connection | gbk |
| Character_set_database | gbk |
| Character_set_filesystem | binary |
| Character_set_results | gbk |
| Character_set_server | gbk |
| Character_set_system | utf8 |
| Character_sets_dir | D: \ mysql6.0 \ share \ charsets \ |
+ -------------------------- + ------------------------------- +

View the content in the database.

Mysql> select * from test;
+ ------ + -------- +
| Id | name |
+ ------ + -------- +
| 1 | Li Xiaofeng |
| 2 | Wang Xiaofeng |
| 3 | Zhang Xiaoxue |
| 4 | Wang Xuefeng |
| 5 | Lu Yun |
| 6 | peach blossom girl |
| 1 | demo1 |
| 2 | demo2 |
| 3 | demo3 |
+ ------ + -------- +
9 rows in set (0.00 sec)

Related Article

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.