Linux下MySQL5.5/5.6的改动标识符集编号为UTF8(处理

PS:昨日一朋友碰到mysql 5.5汉语错码难题,要我处理。处理了,有一个关键点难题在网上没有人说,我也小结一下。

一、登陆MySQL查询用SHOW VARIABLES LIKE character% 下标识符集,显示信息以下:


+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+
二、非常简单的极致改动方式,f文档中的标识符集键值(留意配备的字段名关键点):

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]字段名是有差别的。这一点在网络上没有人意见反馈过。

应用SHOW VARIABLES LIKE character% 查询,发觉数据信息库编号全已改为utf8。


+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+


4、假如上边的都改动了还错码,那剩余难题就一定在connection联接层上。处理方式是在推送查寻前实行一下下边这句话(立即写在SQL文档的最前边):
SET NAMES utf8

它非常于下边的三句命令:

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

在网上许多别的方式不可以完全处理这一难题,这一能够极致处理!