Home > Database > Mysql Tutorial > body text

mysql数据库中文乱码解决方法

WBOY
Release: 2016-06-07 17:51:29
Original
1129 people have browsed it

文章分享了自己在网站开发时mysql数据库中文乱码解决方法,有碰到相同问题的朋友可以参考一下下哦。

字符集问题会导致乱码,从而消耗开发者蛮多精力。针对的用户,按如下AB所示的方法操作,即可避免大部编码问题

A.mysql安装时的默认编码是latin1,此时要注意需要将其手动更改为utf8.

B. 修改my.ini文件

My.ini中的[mysql]对应的是客户端参数

    [mysqld]中对应的刚是数据库后台服务的相关参数

   两者都有default-character-set属性,将client端设置为GBK编码,后台数据用utf8存储,可以满足大部国内开发者的开发环境需求。

 

补充说明1.

对于“将client端设置为GBK编码”的补充说明

目前Windows的内核已经支持Unicode字符集,内核上可以支持全世界所有的语言文字,同时用Windows使用代码页(codepage)来适应各个国家和地区。codepage可以理解为我们在普通的cmd窗口或文本编辑器中输入文字时的默认编码。这也是数据库客户端的显示编码字符集必须与my.ini设置一致的原因,如果将utf8编码在cp936表中进行查找,势必得到乱码。

GBK对应的codepage是CP936。

查看方法为cmd->chcp,如下图结果,可以确认客户端默认输入编码为936

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!