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