mysql中文乱码的完美解决方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql中文乱码的完美解决方案相关的知识,希望对你有一定的参考价值。

问题描述: mysql插入中文时显示为乱码或"?"号

解决方案:

修改mysql的my.ini配置

[mysql]
default_character_set=utf8
[mysqld]
character_set_server=utf8

 

 

 

 

//以下内容为测试记录内容,完全可以忽略不读,但为了增加可信度,还是附上了:)

show variables like "%char%";

默认:

+--------------------------+---------------------------------------------------+

| character_set_client     | gbk                                               |

| character_set_connection | gbk                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | gbk                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(本次启动有效,治标不治本)

set names utf8:

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效)

my.ini

[client]

default_character_set=utf8

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效,效果同[client]修改)

my.ini

[mysql]

default_character_set=utf8

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效,中文完美显示,避免了每次Insert数据前都先要set names utf8一下)

my.ini

[mysql]

default_character_set=utf8

[mysqld]

character_set_server=utf8

+--------------------------+---------------------------------------------------+

| 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       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

以上是关于mysql中文乱码的完美解决方案的主要内容,如果未能解决你的问题,请参考以下文章

完美解决php+mysql汉字存储乱码问题

mysql在cmd里中文乱码解决办法

xmind中文乱码的完美解决方案

MobaXterm中文乱码问题解决

完美解决R完中文无法显示或R语言中文乱码

Matplot中文乱码完美解决方式