1、mysql错误代码1366
向表中添加数据,出现1366错误代码
出错原因:检查数据库此字段的字符集与整理字符集是否与SQL语句传递数据的字符集相同;不相同则会引发MySQL1366错误。
(1)、使用语句查询当前表的各个字段状态
SHOW FULL COLUMNS FROM student;
(2)、发现Collation列中有的字段含有非utf8项,应使用如下语句进行修改
ALTER TABLE student CHANGE studentno studentno VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; ALTER TABLE student CHANGE studentname studentname VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; ALTER TABLE student CHANGE loginpwd loginpwd VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; ALTER TABLE student CHANGE sex sex VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; ALTER TABLE student CHANGE phone phone VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''; ALTER TABLE student CHANGE email email VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '';
(3)、现在可以向数据库中添加想要的数据了