在Laravel项目的 storages/logs/Laravel.log看到的错误信息片段:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x91\x8B\xF0\x9F...' for column 'name' at row 1

出错原因:检查数据库此字段的字符集与整理字符集是否与SQL语句传递数据的字符集相同;不相同则会引发MySQL1366错误。

解决方法:

#1.检查数据表所有字段的状态
mysql> SHOW FULL COLUMNS FROM tdb_goods;
#2.发现collatioin项非utf8,需要进行修改,使用如下的语句
mysql> alter table tdb_goods change goods_name name varchar(100) character set utf8 collate utf8_unicode_ci not null default '';
#3.检查数据表所有字段的状态
mysql> SHOW FULL COLUMNS FROM tdb_goods;
mysql> select * from tdb_goods\g

mysql语句的\g等同于;,\G:将查询到的横向表格纵向输出,方便阅读


未进行修改my.cnf,下面内容可跳过。记录自己的了解和尝试

参考别人的博文,说是 mysql的配置sql-model不正确导致的,需要将 my.cnf中的sql-model中的STRICT_TRANS_TABLES删除

STRICT_TRANS_TABLES(存储引擎启用严格模式,非法数据值被拒绝)

我的mysql配置文件是在/etc/my.cnf

sudo cp /etc/my.cnf /etc/my.cnf_bak190628
sudo vim /etc/my.cnf

[mysqld]
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

改为

[mysqld]
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

删除了STRICT_TRANS_TABLES,然后重启 mysql


不修改 my.cnf (在不清楚my.cnf存放的位置时可使用的,但是在mysql服务重启之后,这个设置会失效)

show variables like 'sql_mode';

set global sql_mode='ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
References
  1. SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'xxx' at row 1
  2. mysql出现ERROR 1366 (HY000):的解决办法
  3. mysql中\G和\g的作用
  4. MySQL中\g和\G的作用
  5. How do I find the MySQL my.cnf location

SQLSTATE[HY000]: General error: 1366 Incorrect string value的更多相关文章

  1. SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x90\xA3\xF0\x9F...' for column

    在做微信公众号保存用户数据时出现这种错误,一直不知道是哪里的原因,后来发现那个用户昵称带着一只兔子表情,由于数据库编码限制不能保存数据,所有需要先编码, 用PHP的函数就是base64_encode, ...

  2. mysql General error: 1366 Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...' for column 'dianpumiaoshu' at row 1 解决方法

    mysql General error: 1366 Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...' for column 'dianpumi ...

  3. string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn't have a default value"

    mysql版本是5.7.26,在插入数据时报错: string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn ...

  4. legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a default value

    legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a ...

  5. SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='

    在操作MySQL数据库时,报“ error code [1267]; Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_gen ...

  6. SQLSTATE[HY000]: General error: 1030 Got error 28 from storage engine

    今天上课程化平台考试,输入平台网址突然报这个错误 可以先df -h 发现/tmp文件使用满了 ,清理下不需要的临时文件即可

  7. MySQL报错: SQLSTATE[HY000]: General error: 1030 Got error 28 from storage engine

    执行命令:df -h [root@iZ25z6qcmrhZ ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/xvda1 40G 38G ...

  8. SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction 解决方法

    SHOW FULL PROCESSLIST; KILL 263071

  9. corresponding SQLSTATE values general error

    http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html B.3 Server Error Codes and Message ...

随机推荐

  1. yield迭代器的使用

    class Program { static void Main(string[] args) { List<Student> students = new List<Student ...

  2. css3条纹进度条

    新建div,取名progress,如下 <div class="progress"></div> 在里面插入条纹进度条,以及进度显示文本进度: <di ...

  3. grunt中调用webpack

    项目中一些很老的技术需要运用webpack管理,这时候必须使用grunt+webpack 配合使用 .做个笔记,不限多说直接上代码 grunt结合webpack 下面是 Gruntfile.js co ...

  4. Atcoder arc092

    E-Both Sides Merger 给你一个序列,支持两种操作,直到序列中只有一个数时停下来,使得剩下数最大,并输出选数方案. 操作1:扔掉一个最前端或最后端的元素.操作2:选取一个不在边界上的元 ...

  5. 单向连通图 Going from u to v or from v to u? poj2762

    http://poj.org/problem?id=2762 强连通求子图和子图关系 + 子图关系是链式结构 #include <cstdio> #include <cstdlib& ...

  6. leetcood学习笔记-235-二叉搜索树的最近公共祖先

    题目描述: 利用二叉搜索树的特点,如果p.q的值都小于root,说明p q 肯定在root的左子树中:如果p q都大于root,说明肯定在root的右子树中,如果一个在左一个在右 则说明此时的root ...

  7. nextJS使用注意事项

    项目参考 nextJs-yicha 1. 采用方案 create-next-app.antd (1)安装 npx create-next-app --example with-ant-design m ...

  8. BZOJ 4517: [Sdoi2016]排列计数(组合数学)

    题面 Description 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 m ...

  9. TYVJ1061 Mobile Service

    P1061 Mobile Service 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那 ...

  10. NX二次开发-UFUN创建倒角UF_MODL_create_chamfer

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建块 UF_FEATURE_SIGN S ...