将mysql默认编码改为UTF8

windows:
a. WIN+R  net stop mysql  关闭mysql服务
b. 复制my-dafault.ini,重命名为my.ini,进入里面
UBUNTU:
** sudo vim /etc/mysql/my.cnf **进入
 
执行以下操作:

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%' 可查看mysql编码方式,修改完成后是这样的:

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

posted on 2016-05-19 13:58  miranda_tang  阅读(6997)  评论(0编辑  收藏  举报