fedora 中设置mysql编码

我的操作系统是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

Java代码  fedora 中设置mysql编码
  1. [mysqld]  
  2. datadir=/var/lib/mysql  
  3. socket=/var/lib/mysql/mysql.sock  
  4. # Disabling symbolic-links is recommended to prevent assorted security risks  
  5. symbolic-links=0  
  6. character_set_server=utf8  
  7. log-error=/var/log/mysqld.log  
  8. pid-file=/var/run/mysqld/mysqld.pid  
  9.   
  10. [mysqld_safe]  
  11.   
  12. #  
  13. # include all files from the config directory  
  14. #  
  15. !includedir /etc/my.cnf.d  
  16.   
  17. [mysql]  
  18.   
  19. default-character-set=gbk  
  20.                                                  

 我在[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\_%';

上一篇:C/C++指针做参数的内存泄露问题


下一篇:Javascript多线程引擎(八)