First, login MySQL view with show VARIABLES like ' character% '; The following character set, shown below:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
The default character set for Character_set_database and Character_set_server is still latin1.
Two, the simplest perfect modification method, modifies the character set key value in the MySQL my.cnf file ( note the field details of the configuration ):
1, in [client] Add Default-character-set=utf8 to the field as follows:
[client]
Port = 3306
Socket =/var/lib/mysql/mysql.sock
Default-character-set=utf8
2, add Character-set-server=utf8 in the [mysqld] field as follows:
[mysqld]
Port = 3306
Socket =/var/lib/mysql/mysql.sock
Character-set-server=utf8
3, in [MySQL] Add Default-character-set=utf8 to the field as follows:
[MySQL]
No-auto-rehash
Default-character-set=utf8
After the
modification is complete, service MySQL Restart restarts the MySQL services to take effect. Note: The [mysqld] field differs from the [MySQL] field. This is no one on the internet feedback.
Use show VARIABLES like ' character% '; view, found that the database encoding has been changed to UTF8.
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
MySQL 5.5 Chinese garbled problem