The following articles mainly describe the actual solutions to MySQL Chinese problems. We all know that encoding and garbled problem of MySQL Chinese problems have always plagued computer workers, it can be said that the problem of encoding and garbled code in MySQL is imminent.
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/ |
- +--------------------------+----------------------------+
2 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 values listed above are the default values of the system. lanti does not support Chinese, so we change it to urf8.
Next we will modify the encoding methods of these four layers:
1. In the [MySQL Chinese problem] 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 url of your database connection address:
? UseUnicode = true & characterEncoding = UTF-8/hibernate? UseUnicode = true & characterEncoding = UTF-8
Of course, if you use a MySQL management tool for Chinese problems, 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.
Edit recommendations]