简记mysql中文乱码(插入变成??)的问题.

mysql插入汉字出现问题.

首先检查你的文件,是否用相同字符编码.比如gbk,gb2312,utf8(utf-8?[开个玩笑]),如果你的代码文件编码和数据库不统一,插入变成??很正常.解决办法就是统一编码.

其次检查你的数据库属性是否正确.

show variables like ''char%''; 这句代码查看你的数据库编码属性.

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       | C:\Program Files\MySQL\MySQL Server 5.5\share\charsets\ |

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

 通常使用如下sql即可修改编码

MYSQL>set character_set_client = 'gbk' ; 



MYSQL>set character_set_connection = 'gbk' ; 



MYSQL>set character_set_results= 'gbk' ; 



MYSQL>set character_set_server= 'gbk' ; 

  但是问题在于这样设置之后未必能生肖.当你重新打开cmd检测的时候发现你设置的并没有生效.

最后的措施就是到数据库安装目录修改my.ini

大约55行

[mysql]



default-character-set=utf8

  

大约79行

# The default character set that will be used when a new schema or table is

# created and no character set is defined

character-set-server=utf8

  

你可能感兴趣的:(mysql)