Home >Database >Mysql Tutorial >深入剖析MySQL数据库字符集的出错现象_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:56:52893browse

  首先,我们来看一下错误示例:

  Illegal mix of collations (gbk_chinese_ci,IMPLICIT)

  and (gbk_bin,IMPLICIT) for operation '=',

  SQL State: HY000, Error Code: 1267

  原因:

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

  处理方法:

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

  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=gbk;

  也可以用下面的方法:

  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`)

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