Query mysql code and solve mysql garbled code problems

Source: Internet
Author: User

The garbled mysql problem is a headache, sometimes on the console, and sometimes on the service side.

MySQL can refine the character set designation to a database, a table, and a column. Traditional programs do not use such complex configurations when creating databases and data tables. They use default configurations.

(When installing mysql, especially using the integrated environment: for example, if you do not set a password for appserver wampserver, open the console and press enter .)

First, how to query mysql encoding:

Use the command statement:

Mysql> show variables like 'character % ';

Second, to solve the garbled code problem, it may be the encoding problem. You can modify the encoding as follows:

Problem 1: garbled characters are everywhere. The simplest modification method is to modify the character set key value in mysql's my. Ini file:

Default-character-set = utf8
Character_set_server = utf8

The second method is to use the mysql command:

Mysql> SET character_set_client = utf8;
Mysql> SET character_set_connection = utf8;
Mysql> SET character_set_database = utf8;
Mysql> SET character_set_results = utf8;
Mysql> SET character_set_server = utf8;
 
Mysql> SET collation_connection = utf8;
Mysql> SET collation_database = utf8;
Mysql> SET collation_server = utf8;
Problem 2: generally even if the default character set of the table is set to utf8 and the query is sent through the UTF-8 encoding, you will find that the database is still garbled.

The problem lies in the connection layer. The solution is to execute the following statement before sending the query:

Set names 'utf8 ';

It is equivalent to the following three commands:

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set
_ Connection = utf8;

Question 3: I don't know why. After I set all the three character sets on my machine to utf8, the Chinese query results are still garbled, only after character_set_results is set to GBK can Chinese characters be properly displayed from the command line.

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.