字符集的设置,需要打开/etc/my.cnf 加上下面的配置即可
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
设置完成后重启MySQL服务即可
[root@CentOS etc]# service mysql restart
重启后查询数据库状态可以看到已经修改完成。
[root@CentOS etc]# mysql -u root -p
Enter password:
mysql> status
--------------
mysql Ver 14.14 Distrib 5.6.22, for Linux (i686) using EditLine wrapper
Connection id: 4
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.22 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 20 min 47 sec
Threads: 2 Questions: 34 Slow queries: 0 Opens: 68 Flush tables: 1 Open tables: 61 Queries per second avg: 0.027
--------------
mysql>
关于Db characterset的设置,只需要在创建数据库的时候加上 character set utf8 即可;