Chinese garbled characters in mysql _ MySQL

Source: Internet
Author: User
This article mainly shares with you the solution to some mysql Chinese garbled characters encountered in my project, which is very simple and practical. we recommend it to you here. if you need it, you can refer to it. First, the mysql version I used is 5.5.17. recently, the problem is that when I write Chinese data to the database through jdbc in eclipse, what is displayed in the database ?? We had a night to solve this problem (of course, we went to bed after the lights were turned off ( __) In addition, this morning, the headers are all too big. if you change it to another one, an error will be reported when you write Chinese directly to the database (I will post the error page) as follows:

In fact, looking back, garbled text is nothing more than modifying the my. ini file in the mysql installation file and the db. opt file in data. the specific modification is as follows:

Modify the file in the my. ini file:

[client] port=3306[mysql]default-character-set=gbk[mysqld] character-set-server=utf8

Modify db. opt in data:

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

Now, after modifying the file, you need to rewrite and start the mysql service. enter mysql and enter the following command:

Show variables like "% colla % ";

Then enter show varables like "% char % ";
If the above results are the same, the setting is successful.

In addition, if you encounter an SQL exception when writing Chinese data to the database from eclipse, you can enter the following command in cmd:

Show create database db; (db is the database name) you can view the database encoding. if it is still latin1, you can use the following command to modify the database encoding:
Alter database db default character set utf8;

In this way, you can change the database encoding to utf8.

Now, when you connect to mysql through jdbc, you can add Chinese characters to mysql at will.

The above is the garbled problem I encountered in using mysql. I hope to provide some reference for those who encountered the same problem to avoid detours...

Please take a moment to share your article with your friends or leave a comment. 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.