方法一:在命令行输入 set names gbk;
这种方法针对中文有效,日/韩文就无效了。
方法二:彻底解决MySql在UTF8字符集下乱码问题:
安装 MySq时选择字符集为UTF-8
修改MySql安装目录下的my.ini中配置的默认编码:
该文件中有两处这样的配置:default-character-set=latin1
将这两处改成:default-character-set=utf8
在命令行查看字符集编码:show variables like '%char%'; 会看到如下信息:
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/share/charsets/
再输入set names gbk;
在命令行查看字符集编码:show variables like '%char%'; 会看到如下信息:
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
character_sets_dir | D:/MySQL/share/charsets/
此时中文显示正常.
重启mysql服务中文还是显示乱码且全部显示为utf-8除filesystem为binary.输入set names gbk只是将utf-8转换成了 gbk(汉字)状态,所以能看到正常的汉字.