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!