MySQL的编码很复杂,一直也搞不大懂。 参考mysql网站上的一个帖子setting utf8 in my.cnf

修改自己的/etc/mysql/my.cnf,添加了写编码相关的字段 最终版本:

/etc/mysql>cat my.cnf |grep -v ^# 
[client] port = 3306 
socket = /var/run/mysqld/mysqld.sock 
default-character-set = utf8 
[mysqld_safe]
……

后在db shell中查看编码

   mysql> show variables like "%character%";show variables like "%collation%";
   +--------------------------+----------------------------+
   | 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/ | 
   +--------------------------+----------------------------+
   8 rows in set (0.00 sec)
   
   +----------------------+-----------------+
   | Variable_name        | Value           |
   +----------------------+-----------------+
   | collation_connection | utf8_general_ci | 
   | collation_database   | utf8_general_ci | 
   | collation_server     | utf8_general_ci | 
   +----------------------+-----------------+
   3 rows in set (0.00 sec)
    

这样编码就统一为utf8了