一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

mysql中文乱码问题解决方法

时间:2011-09-22 编辑:简简单单 来源:一聚教程网

问题现象:

当向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;

热门栏目