MySQL Chinese garbled solution: the MySQL database encoding unified UTF8
To view the database encoding:
Show variables like ' character% ';
Edit/ETC/MY.CNF
[mysql]default-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security Riskssymbolic-links=0default-character-set = Utf8character_set_server = Utf8#lower_case_table_names=1 ignoring case [mysqld_safe]log-error=/var/log/ Mysqld.logpid-file=/var/run/mysqld/mysqld.piddefault-character-set = Utf8[mysql.server]default-character-set = Utf8[client]default-character-set = UTF8
After the modification is complete, service MySQL restart restart the MySQL services to take effect. Note: The [mysqld] field differs from the [MySQL] field.
If the above are modified and garbled, then the remaining problem must be on the connection connection layer. The workaround is to execute the following sentence before sending the query (write directly to the front of the SQL file):
SET NAMES ‘utf8‘;
It is equivalent to the following three-sentence instruction:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;
Execute show variables like ' character% ' as follows to illustrate the success of the modification
Mysql> 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/|+--------------------------+----------------------------+8 rows in Set (0.00 sec)
Linux set MySQL database character set UTF8