We have introduced some of the actual solutions for MySQL Garbled text in some previous articles. Today we mainly describe the experiences of MySQL Garbled text processing and the actual solutions, the following is an analysis of its specific content. I hope you will gain some benefits.
Summary of MySQL garbled processing:
(1) Chinese characters are processed normally in java. Displaying garbled characters in the cmd client is a problem with character sets.
(2) The length of the field is long enough. However, when a Chinese character is inserted, the system prompts com. MySQL. jdbc. MySQLDataTruncation: Data truncation: Data too long for column.
(3) garbled characters are the final issue of character sets. We should consider the following aspects from Character Set settings: server, client, database, connection, and results.
Solution
(1) modify the my. ini (MySQL Server Instance Configuration file)
- # CLIENT SECTION
- [client]
- port=3306
- [MySQL]
- default-character-set=gbk
- # SERVER SECTION
- [MySQLd]
- default-character-set=gbk
(2) modify the db. opt configuration file under the corresponding database directory in the data Directory
- default-character-set=gbk
- default-collation=gbk_chinese_ci
(3) Character Set specified in the database connection string
URL = jdbc: MySQL: // yourIP/college? User = root & password = yourPassword & useUnicode = true & characterEncoding = gbk
Note: in MySQL 4.1.0, useUnicode = true & characterEncoding = gbk must be added. if the version is later than 5.0, it does not matter if you do not add it!
(4) Specify the character set when creating a database
- create database yourDB CHARACTER SET gbk;
(5) On the doscommand, Set
- set names gbk
Okay. Check the above four settings. It should be OK! Such
Com. MySQL. jdbc. MySQLDataTruncation: Data truncation: Data too long for column.