Home >Database >Mysql Tutorial >使用MySql和php出现中文乱码的解决方法_MySQL

使用MySql和php出现中文乱码的解决方法_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 14:04:40817browse
 

一.gb2312,gbk,utf8等支持多字节编码的字符集都可以储存汉字,gb2312中的汉字数量远少于gbk,而gb2312,gbk等都可在utf8下编码。

 

二.用命令show variables like 'character\_set\_%';查看当前字符集设定:

 

<ccid_code></ccid_code>mysql> show variables like 'character\_set\_%';

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

| Variable_name            | Value  |

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

| character_set_client     | gb2312 |

| character_set_connection | gb2312 |

| character_set_database   | gb2312 |

| character_set_filesystem | binary |

| character_set_results    | gb2312 |

| character_set_server     | latin1 |

| character_set_system     | utf8   |

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

7 rows in set (0.02 sec)

(这里设置的字符是gb2312)

显示中文乱码主要有两个设置:character_set_connection 和character_set_results ,

如果你的这两个设置不支持中文编码,就会出现乱码,只要:set character_set_results =gbk;就设置中文编码了。

三.set names charset_name;可以一次性设置客户端的所有字符集。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn