日期:2014-05-16  浏览次数:20857 次

mysql 编码 解决mysql乱码问题
   今天发现,往mysql数据库里插入内容的时候总是会有中文乱码,这里我在保证jsp页面传入的内容编码都正确的情况,进行配置,这里我使用的编码是utf8
第一步,在mysql命令行里查看
mysql> show variables like '%char%';
+--------------------------+-------------------------------------+------
| 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       | D:\MySQL Server 5.0\share\charsets\ |......
+--------------------------+-------------------------------------+------
如果此部分为如上所叙述,则不用更改
否则就是使用mysql的命令
      mysql> SET character_set_client = utf8 ;
     mysql> SET character_set_connection = utf8 ;
     mysql> SET character_set_database = utf8 ;
     mysql> SET character_set_results = utf8 ;
     mysql> SET character_set_server = utf8 ;

     mysql> SET collation_connection = utf8 ;
     mysql> SET collation_database = utf8 ;
     mysql> SET collation_server = utf8 ;


第二步、保险起见,在mysql安装目录下,找到my.inf 修改my.inf
vi /etc/my.inf
找到[client]在此行下添加如下一句
default-character-set=utf8

最后,检查
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name             | Value                       |
+--------------------------+----------------------------+
| character_set_client      | utf8                        |