Solve Chinese garbled characters in Mysql, mysql Chinese garbled characters

Source: Internet
Author: User

Solve Chinese garbled characters in Mysql, mysql Chinese garbled characters

Today, I asked about the mysql database Chinese garbled characters on V2EX. First, V2EX is much better than the CSDN Forum module. In an hour, the number of clicks has exceeded 500, there are also many people who help answer the question.

The following is my question:

---------------------------------------------------------

The whole process of the project is utf8. The data written into the database by hibernte is displayed normally under the consystemic interface of myeclipse. Why is the Chinese name displayed in the dos window of the database garbled. Note: All my database configurations are utf8

Then I tried to manually insert Chinese characters using the insert statement in the dos window. The result is error1406, which cannot be inserted. Then I checked the Chinese characters inserted by the program and showed garbled characters.

Solution. the configuration in the INI file is changed to GBK, and the correct Chinese characters are displayed in the dos window. I want to ask why GBK can read Chinese Characters Since the database is UTF-8 encoded, utf8 does not work. Does the dos window not support utf8 display, so Chinese characters are garbled?

----------------------------------------------------------

After thinking about it, it should be the problem of displaying the DOS window. Now, the database is used for graphical management operations. If you want to use a command prompt, you can only set names gbk first; if you don't need to use it, enter set names utf8. The reason for this switch is that I want to keep all the settings in the utf8 mode to avoid the possible troubles. This should be the current solution.

Enter "set names UTF8;" in the MySQL command line ;"
The sentence equals:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8
The Running Mode in mysql is
Information Input path: client → connection → server;
Information output path: server → connection → results.
In other words, taking garbled output as an example, the utf8 data in the server is passed into the connection, and the imported results is still utf8, And the dos window transfers results. If the two character sets are incompatible, such as gbk and utf8, the conversion process will be irreversible and destructive, so it will be garbled.
Again, there will be no garbled characters. Each path must undergo three character set encoding changes. For utf8 data in the server, the incoming connection is converted to gbk, and the imported results is still encoded in GBK. The DOS window transfers results. The default dos encoding method is GBK, which is the same, there will be no garbled characters.
Therefore, I used to always insert SQL statements that contain Chinese Characters in error1406. That is why.
In addition, I set the encoding method of my database to utf8 when I created it, so the encoding method of my database is utf8, then there will be no errors when other tools read data.
This is why a set names gbk (for dos windows) or set names utf8 (for pages and other things encoded with utf8) is entered with a garbled code ), the garbled characters disappear.

Of course, set names GBK. If you shut down the database and restart it, it will be restored to the original one, but it doesn't matter. In the future, we will use graphical management tools, I don't need to use the dos window too much. I will use the linux development environment after several years of experience.

----------------------------------------------------------------------------------

I learned other knowledge about databases today:

View the current database encoding format:
Show variables like 'character _ set_database ';
View character encoding

Show variables like 'character % ';

Set the server encoding method

Set character_set_server = utf8

The difference between varchar and nvarchar is that varchar is a character nvarchar is a Unicode string. The former does not support Chinese characters, and the latter supports Chinese characters.

Schema in mysql

Http://blog.csdn.net/kimsoft/article/details/4627520
Mysql 1406 error is caused by different encoding methods.

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.