The solution of Chinese garbled in MySQL

Source: Internet
Author: User

Today in V2ex asked the next encountered MySQL database Chinese garbled problem, first said, V2ex than CSDN forum module much better, one hours of click on the breakthrough 500 times, but also a lot of people to help answer.

And then here's the question I asked:

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

The whole project is utf8,hibernte write into the database of the data out to MyEclipse Consle below the display is normal, why in the database that DOS window below the Chinese name is garbled. Note: All configurations of my database are UTF8

Then I try to manually insert a DOS window in Chinese, the result is error1406, plug in, and then see the program inserted in the Chinese display garbled.

After the solution: I put the My.ini file in two configurations to GBK, and then the DOS window shows the correct Chinese, I want to ask is that since the database is UTF8 code, why GBK can be read in Chinese, UTF8 will not, is not a DOS window does not support the display of UTF8, so Chinese garbled?

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

Think about, almost should be the DOS window display problem, now use the database to manage the operation with graphical, if you want to use the command prompt operation, you can only set names GBK; then input a set names UTF8; The reason for this switch is because I want to keep all the UTF8 way to avoid the possible trouble, this should be the current solution.

MySQL command line input "SET NAMES UTF8;"
The side of the sentence equals:
SET character_set_client = UTF8;
SET character_set_results = UTF8;
SET character_set_connection = UTF8
The operating mode in MySQL is
Information input path: client→connection→server;
Information output path: Server→connection→results.
In other words, with garbled output as an example, the server in the UTF8 data, incoming connection, the incoming results still for the Utf8,dos window results turn around. If the two character sets are incompatible, such as GBK and UTF8, the conversion process is irreversible and destructive, so it will be garbled.
Again, there is no garbled situation, each path has to change the character set encoding 3 times. Server UTF8 data, incoming connection to GBK, incoming results, encoding is still gbk,dos window results turn, DOS default is GBK encoding method, this is the same, will not appear garbled.
So I always error1406, inserting the SQL statement containing Chinese, that is the truth.
In addition, my database encoding, I was created in order to UTF8, so my database encoding method is UTF8, then my other tools can read the error.
This is why each time a garbled, enter a sentence set names GBK (for DOS window), or enter a set names UTF8 (for the page and so on UTF8 encoded things), garbled disappears the reason for it.

Of course, set names GBK; Turn off the database and restart the words will be restored to the original, but this does not matter, after almost all with a graphical management tool, it will not be used to DOS window, and so on after their own technology mature, after a few years of experience, with the development environment of Linux.

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

Learn more about the database today:

To view the current database encoding format:
Show variables like ' character_set_database ';
viewing character encodings

Show variables like ' character% ';

Set the encoding for the server

Set Character_set_server=utf8

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

The specific meaning of the schema in MySQL

http://blog.csdn.net/kimsoft/article/details/4627520
MySQL's 1406 error is due to the different coding methods described above.

The solution of Chinese garbled in MySQL

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.