日期:2014-05-16 浏览次数:20705 次
如果mysql出现中文乱码,一般是字符集没有设置为utf8导致的。需要设置客户端字符集和服务端字符集为utf8。在windows系统中Mysql的配置文件为my.ini。
?
在my.ini中找到[mysql]
?
增加以下内容:
?
?
default-character-set=utf8
?
在my.ini中找到[mysqld],将default-character-set改为以下内容:
?
default-character-set=utf8
?
之后重启mysql服务器。
?
在mysql的命令行中输入以下命令获得当前mysql使用的字符集:
?
mysql> show variables like 'character_set_%';
+--------------------------+-----------------------------------------+
| Variable_name??????????? | Value?????????????????????????????????? |
+--------------------------+-----------------------------------------+
| character_set_client???? | utf8??????????????????????????????????? |
| character_set_connection | utf8??????????????????????????????????? |
| character_set_database?? | utf8??????????????????????????????????? |
| character_set_results??? | utf8??????????????????????????????????? |
| character_set_server???? | utf8??????????????????????????????????? |
| character_set_system???? | utf8??????????????????????????????????? |
| character_sets_dir?????? | /usr/local/mysql5/share/mysql/charsets/ |
+--------------------------+-----------------------------------------+
?
在mysql的命令行中输入以下命令获得当前mysql使用的连接校对:
?
mysql> show variables like '%collation%';
+----------------------+-----------------+
| Variable_name??????? | Value?????????? |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database?? | utf8_general_ci |
| collation_server???? | utf8_general_ci |
+----------------------+-----------------+
?
如果你输入以上两个命令的结果和上面的输出结果一样,那么中文就不会乱码。