Recently, when using MySQL, there was a strange problem with garbled characters, and I started to see that there were some problems with the MySQL character set.
Modified configuration file/etc/my.cnf
[mysqld]character-set-server=utf8
> Show variables like "character%";
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
But found that did not solve the problem of garbled, and find the relevant information found, in fact, MySQL UTF8 character set, our domestic default choice: Utf8_general_ci instead of utf8_unicode_ci, but the utf8 of the terminal is Utf8_unicode_ Ci
So this creates a conflict, and then modifies the configuration file.
[mysqld]init_connect=‘SET collation_connection = utf8_unicode_ci‘init_connect=‘SET NAMES utf8‘character-set-server=utf8collation-server=utf8_unicode_ci
After the modification, the program still does not solve the garbled problem.
After observation, it was found that although the configuration file was set, the character set will change strangely after each startup of MySQL.
The configuration file is then modified again.
[mysqld]init_connect=‘SET collation_connection = utf8_unicode_ci‘init_connect=‘SET NAMES utf8‘character-set-server=utf8collation-server=utf8_unicode_ciskip-character-set-client-handshake
Skip-character-set-client-handshake skips characters to set the client handshake.
The documentation is explained below
--character-set-client-handshakeDon‘t ignore character set information sent by the client. To ignore client information and use the default server character set, use --skip-character-set-client-handshake; this makes MySQL behave like MySQL 4.0
MySQL Default character Set issues