Home >Database >Mysql Tutorial >mysql5.5字符集设置的一点变化(对于中文乱码问题,需要设置mysq_MySQL

mysql5.5字符集设置的一点变化(对于中文乱码问题,需要设置mysq_MySQL

WBOY
WBOYOriginal
2016-05-31 08:47:411138browse

工作中因为字符集问题没少头疼,还犯过一次错误,还好拯救及时,没有发生重大事故,唉,弄清楚点还是非常有必要的:

例如我的工作环境为CTR+redhat5+mysql5.5

在导入sql语句的时候必须要注意三个地方:(此处以UTF-8字符集为例)

字符集问题:

1、crt中要改为UTF-8  新宋体

2、linux系统字符集 locale要改为

LANG=en_US.UTF-8

3、mysql中 client要该为:

mysql > /s

...

Server characterset:    utf8

Db     characterset:    utf8

Client characterset:    latin1

Conn.  characterset:    latin1

...

mysql > set names utf8;                              此处为临时改客户端的字符集为UTF-8,这个由于历史遗留问题造成的,只能临时改。

Query OK, 0 rows affected (0.00 sec)

mysql > /s

...

Server characterset:    utf8

Db     characterset:    utf8

Client characterset:    utf8

Conn.  characterset:    utf8

...

另一种情况,可以永久生效字符集,方法如下:

对于中文乱码问题,需要设置mysql字符集:

用find命令查找cnf文件。记得不要去找my.cnf因为它不一定存在,而应该找*.cnf。

# find / -name '*.cnf'

/usr/share/doc/MySQL-server-5.5.27/my-huge.cnf

/usr/share/doc/MySQL-server-5.5.27/my-large.cnf

/usr/share/doc/MySQL-server-5.5.27/my-medium.cnf

/usr/share/doc/MySQL-server-5.5.27/my-small.cnf

/usr/share/doc/MySQL-server-5.5.27/my-innodb-heavy-4G.cnf

/usr/share/doc/kpathsea-2007/kpathsea_defaults/texmf-kpathsea-defaults.cnf

/usr/share/mysql/my-huge.cnf

/usr/share/mysql/my-large.cnf

/usr/share/mysql/my-medium.cnf

/usr/share/mysql/my-small.cnf

/usr/share/mysql/my-innodb-heavy-4G.cnf

/etc/pki/tls/openssl.cnf

找到之后,复制一个出来

# cp /usr/share/mysql/my-huge.cnf  /etc/my.cnf

打开my.cnf修改编码

# vi /etc/my.cnf

mysql5.5以下:

在[mysqld]下添加

default-character-set=utf8

在[client]下添加

default-character-set=utf8

mysql 5.5 改为:

[client]

default-character-set = utf8

[mysqld]

character-set-server = utf8

然后重启mysql

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn