This is a problem.
Reprinted from: http://www.iteye.com/topic/239698
I have read many questions about MySQL encoding settings and garbled characters.ArticleAfter repeated debugging, I finally solved a heart disease and finally solved my hate. It is summarized as follows.
MySQL 4.1 character set support has two aspects: Character Set and collation ). The support for character sets is refined to four levels: Server, database, table, and connection ). Our final goal is to make these four levels of conversions support Chinese encoding. The following uses utf8 as an example.
1. First, view the character set and sorting method of the system. If you want to view the character set and sorting method of a specific database, you should first select the database, mysql> Use databasename;
Mysql> show variables like ''character _ SET _ % '';
+ -------------------------- + ---------------------------- +
| Variable_name | value |
+ -------------------------- + ---------------------------- +
| Character_set_client | Latin1 |
| Character_set_connection | Latin1 |
| Character_set_database | Latin1 |
| Character_set_results | Latin1 |
| Character_set_server | Latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/MySQL/charsets/|
+ -------------------------- + ---------------------------- +
7 rows in SET (0.00 Sec)
Mysql> show variables like ''collation _ % '';
+ ---------------------- + ------------------- +
| Variable_name | value |
+ ---------------------- + ------------------- +
| Collation_connection | latin1_swedish_ci |
| Collation_database | latin1_swedish_ci |
| Collation_server | latin1_swedish_ci |
+ ---------------------- + ------------------- +
3 rows in SET (0.00 Sec)
The value listed above is the default value of the system. lanti does not support Chinese characters, so we change it to urf8.
Next we will modify the encoding methods of these four layers:
1. In the [mysqld] section of the my. cf file, set:
Default-character-set = utf8
This statement sets character_set_client, character_set_connection _, and character_set_results to utf8, including encoding of the corresponding arrangement.
Character_set_server is the system code, which does not need to be changed.
Of course, another way to change the character_set_client, character_set_connection _, and character_set_results encoding methods is: Set names "utf8 ";
It serves the following purposes:
Set character_set_client = utf8;
Set character_set_results = utf8;
Set character_set_connection = utf8;
2. Change the encoding method of the database.
Alter database databasename Character Set utf8;
Last night, we changed the encoding of the database. Of course, there are 10 thousand other methods besides this method, that is, we can see that it is not utf8, you only need to change the corresponding encoding to utf8. Format: Set character_set_client = utf8;
3. Whether you are Web programming or desktop programming, the suffix must be included in the connection URL of your database :? Useunicode = true & characterencoding = UTF-8/hibernate? Useunicode = true & characterencoding = UTF-8
Of course, if you use MySQL management tools such as MySQL Yog and MySQL manager, you can set your database settings directly in a visual environment. Of course, this is only limited to the database settings.