本节内容:
fedora系统中设置mysql/ target=_blank class=infotextkey>mysql数据库编码
linux操作系统为: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
修改完编码之后(www.jb200.com):
复制代码 代码示例:
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_%';