百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> mysql中文乱码问题解决方法
分享文章到:

mysql中文乱码问题解决方法

发布时间:01/15 来源: 浏览: 关键词:
mysql中文乱码是php jsp初学者常碰到的事情,解决方法有很多,下面我们介绍一下在my.cnf中配置的方法

问题现象:

当向mysql教程5.5插入中文时,会出现类似错误

ERROR 1366 (HY000): Incorrect string value: 'xD6xD0xCExC4' for column
问题原因:

Db characterset的字符集设成了latin1

1、先确定数据里保存的是否是乱码:
mysql>select * from yourtable;
查看如果是乱码的话,就是你插入数据的时候,当前页面的编码方式和你mysql的编码方式不一致。
2、如果排除了以上乱码的可能,也就是说数据库教程中能正常保存中文,就需要检查你页面显示的编码方式了


解决方案:

找到MYSQL安装目录下的my.ini文件修改:


[client]

port=3306

[mysql]

default-character-set=gbk


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=gbk

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB


参考my.cnf

修改mysql的默认字符集是通过修改它的配置文件来实现的


windows下的mysql配置文件是my.ini,一般在安装目录下(如C:Program FilesMySQLMySQL Server 5.0),可以直接在这个文件里面加上 

default-character-set=gbk #或gb2312,big5,utf8
然后重新启动mysql 

 查看 MySQL 数据库服务器字符集,数据库字符集和客户端字符集 

show variables like '%char%'; 

character_set_client,客户端字符集 

character_set_database,数据库字符集 

character_set_server,服务器字符集 

2. 查看 MySQL 数据表(table) 的字符集 

show table status from tablename like '%countries%'; 

3. 查看 MySQL 数据列(column)的字符集。 

show full columns from tablename; 

4. 查看当前安装的 MySQL 所支持的字符集。 

show char set;

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有11人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板