我的操作系统是fedora 20,安装MySQL 时安装的是MariaDB
最初查看数据库编码时,结果如下:
MariaDB [passwd3]> show variables like 'character\_set\_%';
+--------------------------+--------+
| 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 |
+--------------------------+--------+
修改配置文件:/etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- character_set_server=utf8
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [mysqld_safe]
- #
- # include all files from the config directory
- #
- !includedir /etc/my.cnf.d
- [mysql]
- default-character-set=gbk
我在[mysqld] 节点下添加了:
character_set_server=utf8(ok)
以下是错误的:
default-character-set=utf8(wrong)
在[mysql] (没有该节点的话手动添加)下,增加了:
default-character-set=gbk
修改完编码之后:
MariaDB [(none)]> show variables like 'character\_set\_%';
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
+--------------------------+--------+
7 rows in set (0.01 sec)
注意: (1)default-character-set 是 mysql 自己认识的,而 mariadb5.5 就不认识,相当于变成了character_set_server
(2)查看编码的命令show variables like 'character\_set\_%';