一,登陆mysql用status查看数据库的基本信息
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.3
Connection id: 36
Current database: rinpsi
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 2 min 42 sec
Threads: 1 Questions: 128 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 41 Queries per second avg: 0.790
--------------
可以看到服务器和数据库的字符编码都是latin1,我们的目标是把他们设置成uf8
二,具体步骤就是修改/etc/mysql/my.conf文件中的字符集键值
1.[client]字段
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
##添加
default-character-set=utf8
##添加
2.[mysqld]字段
[mysqld]
#
# * Basic Settings
#
##添加
character-set-server=utf8
##添加
3.[mysql]字段
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
##添加
default-character-set=utf8
三,重启mysql,再次登陆验证修改
service mysql restart
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.46, for debian-linux-gnu (x86_64) using readline 6.3
Connection id: 36
Current database: rinpsi
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 2 min 42 sec
Threads: 1 Questions: 128 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 41 Queries per second avg: 0.790
--------------