MySQL Chinese garbled Solutions

Source: Internet
Author: User

The following articles mainly introduce how to solve MySQL Chinese Garbled text. MySQL Chinese Garbled text is often used in practical applications, resulting in a lot of inconvenience in actual operation, the following article introduces the MySQL Chinese garbled solution. I hope you will have some gains.

I often see MySQL garbled characters in the group, but I don't care much because I have been using oracle and SQL server, I used MySQL yesterday and met the legendary Garbled text ...... Now let's talk about MySQL garbled characters. First you enter your MySQL

Use show variables to view

Here we can see your character set. character_set_server is the server code. Now, the default value is that latin1 must restart the server to change the server encoding. We will first use MySQLadmin-uroot shutdown to close the server, then MySQLd-c gbk starts the server.-C is a shorthand for character_set_server. You can also write it as MySQLd-character_set_server gbk ). after the modification, we can go to MySQL to view the result:

In this way, we can change the server and database encoding to GBK.

Now we can insert a Chinese string, but why is there time?

 
 
  1. Exception in thread "main" com.MySQL.jdbc.MySQLDataTruncation: 

    Data truncation: Data too long for column 'name' at row 1 

MySQL Chinese garbled characters solve the above problem, because you only modified the character encoding of the MySQL server and did not modify the encoding of the database, at this time, you need to manually put the db in the database under the data Directory. change the encoding in opt

 
 
  1. default-character-set=gbk 
  2. default-collation=gbk_chinese_ci 

In this way, you can insert Chinese characters After restarting the server.

But there is another problem at this time, that is, the Chinese characters are displayed in your application, but garbled characters are still displayed in the Command window.

At this time, you should pay attention to the character_set_client character or latin1 shown in the figure above. Of course, it is garbled. Therefore, when you enter the MySQL client program, you must change the default encoding of the client to gbk to display it normally.

You can modify it in MySQL or MySQL-uroot-default-character-set = gbk at login.

In this way, MySQL Chinese garbled characters have been solved.

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.