bitscn.com
mysql默认编码的问题 在mysql的client建数据库:create database bbs2007;use bbs2007; 再建表:create table article (id int primary key auto_increment,pid int,rootid int,title varchar(255),cont text,pdate datetime,isleaf int #1-not leaf 0-leaf); 往表插数据:insert into article values (null, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', now(), 1); 出现这个错误:mysql插入中文时出现error 1406 (22001): data too long for column 'name' at row 1
解决办法是:
先使用命令set names gbk;再执行插入数据的sql语句。原因是因为mysql client默认编码是latin1,不支持中文, set names gbk;是把所有的字段设置成支持中文的编码。 摘自 heirenheiren的专栏 bitscn.com