RedHat linux下修改mysql编码格式为utf8

2010-12-21  张长顺 

(运行如下命令即可查看编码方式)

# mysql -u root -p

Enter password:

mysql > show variables like "character%";

编码显示:

+--------------------------+----------------------------+


| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

1.要修改编码方式则找到mysql安装目录下的配置文件(.cnf文件),一般至少有四个配置文件:mysql-huge.cnf mysql-medium.cnf  mysql-small.cnf mysql mysql-large.cnf  这四个配置文件我们只需拷贝其中一个文件到目录/etc下并重命名为my.cnf,若不拷贝到此目录下则重启Mysql后编码方式又回到默认方式,就是因为这个我整了半天。只要拷贝到/etc目录下就永久的修改了编码方式。

注:先停止mysql服务

2.修改文件my.cnf:

找到客户端配置[client] 在www.linuxidc.com下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8

init_connect=SET NAMES 'utf8'

3.重启Mysql:

# service mysql restart

再查看编码方式即改为了所需编码方式,如下:

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

553°/5535 人阅读/0 条评论 发表评论

登录 后发表评论