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!