mysql几个重要的,与编码相关的配置,默认如下:

mysql> show variables like '%char%';
Variable_name Value
character_set_client utf8
character_set_connectionutf8
character_set_databaselatin1
character_set_filesystembinary
character_set_resultsutf8
character_set_serverlatin1
character_set_systemutf8
character_sets_dir/usr/share/mysql/charsets/

修改方法如下: 修改/etc/mysql/my.cnf,并重启mysql

[mysqld]
character-set-server=utf8  
[client]
default-character-set=utf8  
[mysql]
default-character-set=utf8  

另外,mysql-server只能通过localhost去访问,可以将/etc/mysql/my.cnf中的bind-address改成需要的地址,就可以通过其它机器访问了

本文参考了这篇文章 彻底解决mysql中文乱码