MySQL database default encoding has been utf8, default-character-setutf8, but to the database table to insert Chinese, but always appear .... xB5xA5xD1xA1forcolumn... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it. 1. Number of installations
The default encoding of MySQL database is utf8, and default-character-set = utf8. However, when inserting Chinese characters into the table in the database, it always appears .... \ xB5 \ xA5 \ xD1 \ xA1 for column... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it. 1. Number of installations
The default encoding of MySQL database is utf8, and default-character-set = utf8. However, when inserting Chinese characters into the table in the database, it always appears .... \ xB5 \ xA5 \ xD1 \ xA1 for column... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it.
1. When installing the database, set the character set encoding to utf8.
1. Encoding in the current character set is:
- Server characterset: utf8
-
- Db characterset: utf8
-
- Client characterset: utf8
-
- Conn. characterset: utf8
Create a database:
(1) The operation fails because the Chinese data is inserted.
(2) modify the character set encoding:
- Server characterset: utf8
-
- Db characterset: utf8
-
- Client characterset: gbk
-
- Conn. characterset: gbk
Insert Chinese data. The data is displayed normally.
2. When installing the database, set the character set encoding to gbk.
1. The current character set encoding is:
- Server characterset: gbk
-
- Db characterset: gbk
-
- Client characterset: gbk
-
- Conn. characterset: gbk
And insert Chinese data. The operation is normal and the display is normal.
2. The current character set is encoded as utf8:
- Server characterset: gbk
-
- Db characterset: utf8
-
- Client characterset: utf8
-
- Conn. characterset: utf8
3. The current character set is encoded as utf8:
- Server characterset: gbk
-
- Db characterset: gbk
-
- Client characterset: utf8
-
- Conn. characterset: utf8
Insert Chinese data. The operation cannot be performed.
Conclusion: To insert Chinese characters to a database normally, the following conditions must be met:
1. Set the character set to gbk or utf8 that supports Chinese characters;
2. Set the character sets of the Client Characterset And Conn. Characterset to gbk;
According to the above prompt, I changed:
- SET character_set_client = gbk;
-
- SET character_set_connection = gbk;
Then try again to think about inserting Chinese characters into the database. There is no error in this case. It can be inserted, but the query results are garbled.
Last modified;
- SET character_set_results = gbk;
After that, all the problems are solved, and the insertion can be properly displayed.
View character set commands
5. View Character Set settings
Mysql> show variables like 'collation _ % ';
Mysql> show variables like 'character _ set _ % ';
Modify Character Set
Mysql> set character_set_client = utf8;
Mysql> set character_set_connection = utf8;
Mysql> set character_set_database = utf8;
Mysql> set character_set_results = utf8;
Mysql> set character_set_server = utf8;
Mysql> set character_set_system = utf8;
Mysql> set collation_connection = utf8;
Mysql> set collation_database = utf8;
Mysql> set collation_server = utf8;