Easy-to-language Java C + + MySQL insert Chinese garbled read garbled MySQL garbled

Source: Internet
Author: User
Tags mysql insert

A few days ago should be a friend to help write a data management program, need to use MySQL, since it is a small program, programming language has chosen easy language, sure enough, it was soon done.

But found a very serious problem, easy language comes with MySQL support library by default is GBK encoding and MySQL server is UTF8 will appear garbled!

First I thought of the first way to modify the MySQL server encoding format:

Execute the SQL statement ("set names GBK") to re-test the perfect solution!

------------------------------------------------------It's not that simple.

A few days friends said why will appear garbled ah, I still do not believe, so carried out a wave of tests, found that the small odds of the situation will appear garbled

So I began to look for the reason Ah, here to omit million words ....

After countless tests found that the easy language connection MySQL after the occasional chance of disconnection, but the previously executed "set names GBK" statement will be automatically invalidated

So there will be garbled. So we can only choose the other way.

----------------------------------------------------never garbled

This approach is to change the service-side code directly to GBK, how to change it

There is a file in the server-side MySQL installation directory: My.ini This is the configuration file for MySQL (Can not find a friend remember to show hidden files in the Programdata directory)

Locate the following configuration

[MySQL]//This is the client configuration
Default-character-set=utf8

[MYSQLD]//server configuration

Character-set-server=utf8

Change into

Default-character-set=gbk

Character-set-server=gbk

The MySQL service is then restarted to work perfectly, and this method works in a variety of languages.

Easy-to-language Java C + + MySQL insert Chinese garbled read garbled MySQL garbled

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.