First, view the character set encoding:
Log in mysql
show variables like
'%character%'
;
Second, modify the code:
Edit /etc/my.cnf, after setting the configuration file as follows:
[root@node03 /]# cat /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8
character_set_server=utf8
#lower_case_table_names=1 忽略大小写
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8
[mysql.server]
default-character-set=utf8
[client]
default-character-set=utf8
Third, restart the MySQL service:
service mysql restart
Fourth, if the above were also revised garbled, and that the remaining issues will certainly be on the connection layer connection. The solution is to execute before sending inquiries about the following sentence (written directly in front of the SQL file):
SET NAMES 'utf8';
It is equivalent to the following three instructions:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;
Execution show variables like 'character%' modifications as described below with success
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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)
|