在Centos 7下安装MariaDB简明教程
http://www.2cto.com/database/201311/255324.html
一、登录MySQL查看用show variables like 'character%';下字符集,显示如下:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem |binary|
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
|
character_set_database和character_set_server的默认字符集还是latin1。
二、最简单的完美修改方法,修改mysql的/etc/my.cnf 文件中的字符集键值(注意配置的字段细节):
[plain] view plain copy
1. 在[mysqld]字段里加入character_set_server=utf8,如下:
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character_set_server=utf8
修改完成后,sudo systemctl restart mysqld重启mysql服务就生效。
使用show variables like 'character%';查看,发现数据库编码全已改成utf8。
[sql] view plain copy
+--------------------------+----------------------------+
| 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/ |