[root@flyHome gaoxiang]# find / -iname '*.cnf' -print
/etc/pki/tls/openssl.cnf
/etc/my.cnf
/usr/share/openvpn/easy-rsa/2.0/openssl-0.9.6.cnf
/usr/share/openvpn/easy-rsa/2.0/openssl.cnf
/usr/share/openvpn/easy-rsa/1.0/openssl.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/doc/mysql-server-5.5.18/my-small.cnf
/usr/share/doc/mysql-server-5.5.18/my-large.cnf
/usr/share/doc/mysql-server-5.5.18/my-innodb-heavy-4G.cnf
/usr/share/doc/mysql-server-5.5.18/my-huge.cnf
/usr/share/doc/mysql-server-5.5.18/my-medium.cnf
然后拷贝my-small.cnf、my-medium.cnf、my-huge.cnf、my-innodb-heavy-4G.cnf 其中一个到 /etc/my.cnf 下
[root@flyHome gaoxiang]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@flyHome gaoxiang]# vim /文件所在目录(一般会复制在etc目录下)/my.cnf
在[client]下添加
default-charater-set=utf8
在[mysqld]下添加
collation_server = utf8_general_ci
character_set_server = utf8
保存退出后重启mysqld:
[root@flyHome gaoxiang]#service mysqld restart
完成以上的操作就OK了。
看一下效果:
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+