1、在[client]字段里加入default-character-set=utf8,如下:
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
2、在[mysqld]字段里加入character-set-server=utf8,如下:
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8
3、在[mysql]字段里加入default-character-set=utf8,如下:
[mysql]
no-auto-rehash
default-character-set=utf8
修改完成后,service mysql restart重启mysql服务就生效。注意:[mysqld]字段与[mysql]字段是有区别的。
4、如果上面的都修改了还有乱码,在connection连接上进行编码修改
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;