·一周点击排行
·热点推荐
您的位置:首页 >> 计算机 » 北大青鸟 » 技术文章 » 深入剖析MySQL数据库字符集的出错现象 >> 正文

深入剖析MySQL数据库字符集的出错现象

发布时间:2008-3-3 9:02:00 浏览次数: 351

深入剖析MySQL数据库字符集的出错现象
首先,我们来看一下错误示例:

Illegal mix of collations (gchinese_ci,IMPLICIT)
and (gbin,IMPLICIT) for operation '=',
SQL State: HY000, Error Code: 1267
原因:

数据库的编码与建表时的编码不一样;

处理方法:

如果安装MySQL时设置的编码为j那么建表时可以用下面的方法处理:

CREATE TABLE `teachers` (
id` int(11) NOT NULL default '0',
name` varchar(20) default NULL,
password` varchar(20) default NULL,
department_id` int(11) default NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=g
也可以用下面的方法:

CREATE TABLE `teachers` (
id` int(11) NOT NULL default '0',
name` varchar(20) default NULL,
password` varchar(20) default NULL,
department_id` int(11) default NULL,
PRIMARY KEY  (`id`)
) ;


讨论此主题请进>>: 深入剖析MySQL数据库字符集的出错现象