On the problem of Chinese garbled _mysql in Mysql

Source: Internet
Author: User

First of all, I used the version number of MySQL is 5.5.17, recently encountered the problem is in eclipse through JDBC to the database to write Chinese data, in the database is displayed?? That garbled, in order to solve this problem, engaged in a night (of course, after the lights went to bed (__)) plus the morning, make the head is big, change to cause even to the database directly written in Chinese will be an error (I put the wrong page to post it) as follows:

In fact, now look back, garbled is nothing but to change the MySQL installation files in the My.ini file and data in the Db.opt file, the specific changes are as follows:

Modify the files in the My.ini file to:

[Client] 
port=3306

[MySQL]

default-character-set=gbk

[mysqld] 
Character-set-server=utf8

Now you need to modify the db.opt in data:

Default-character-set=utf8
Default-collation=utf8_general_ci

Okay, now that you've modified the file, now you need to rewrite the start MySQL service, enter the MySQL command:

Show variables like "%colla%";

Then enter show Varables like "%char%";
If the above results are the same as the following figure, it will be successful.

In addition, if you encounter a SQL exception that writes Chinese data from Eclipse to the database, you can enter the command in CMD first:

Show CREATE Database db (DB is the database name) can view the encoding of the database, or, if it is latin1, modify the database encoding using the following command:
ALTER DATABASE DB default character set UTF8;

This allows you to change the encoding of the database to UTF8.

At this point, and then through the JDBC connection, you can very casually add Chinese to MySQL.

The above is I in the use of MySQL encountered garbled problem, I hope to be able to meet the same problem students less detours to provide a point of reference ...

Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!

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.