Especially when I cannot find my. cnf, I should take it seriously.
Author: Fan guanqun
After a few days of desperate Baidu and continuous experiments, I finally solved the problem of Mysql 5.0.22. Online articles are neither too long nor too important, nor too many Windows articles and Linux articles. Next I will talk about my experiences in the following steps:
I. Environment:
// It can be solved in other environments.
Hongqi Linux5.0, java1.5.0-beta2, mysql 5.0.22, hibernate2.1
Ii. Symptoms
1. When the data in the program is stored in the database, the Chinese character becomes a question mark.
2. When reading data from the database, Chinese words are still a bunch of greetings.
3. Solution steps
If (my. cnf exists in the/etc directory ){
Open the my. cnf file and find the word [mysqld.
// Explanation: default-character-set = gb2312 is the default character set for the database.
// The equal sign can be followed by other characters, such as UTF-8.
// If this row is not written in such a file, the default Character Set of the database is litan.
// This is the reason for Chinese garbled characters
Add a default-character-set = gb2312 row under it.
Save the my. cnf File
} Otherwise, if (my. cnf does not exist in the/etc directory ){
// Explanation:
// The installation directory of mysql is/usr/share/mysql if you use rpm for installation.
// If you decompress the package without installation, it will be in the decompressed folder.
Locate my-small.cnf, my-medium.cnf in the installation directory of mysql
, My-large.cnf and other similar naming file security needs to take;
// Explanation: I only need a small default configuration for mysql.
I get my-small.cnf
Open the my-small.cnf file and find the word [mysqld.
Add a default-character-set = gb2312 row under it.
Save as my. cnf File
Copy my. cnf to the/etc directory.
}
Restart the computer. (I want to restart mysql. If you haven't tried it, you can try it ).
For example, if the database used in your program is testdb, You need to delete testdb and recreate testdb and all tables in it.
Mysql now supports Chinese, without having to modify code writing or other settings. Note that you must delete the test database and recreate the test and all the tables in it. Otherwise, garbled characters will occur.