MySQL数据库插入中文时出现Incorrect string value: '\xE6\x97\xB7\xE5\x85\xA8' for column 'sz_name' at row 1
今天在开发时候出现了这个问题
Incorrect string value: '\xE6\x97\xB7\xE5\x85\xA8' for column 'sz_name' at row 1
场景,往MySQL数据库的表中插入中文参数,抛出了这个异常
我用sqlyog执行该段代码时候发现只是出现警告,并没有出现error,但是在代码里面执行抛出了异常,说明管理工具sqlyog对有些约定不是那么严格,而代码中就会报错。提醒自己,以后写sql时候不能忽略管理工具中出现的警告。
解决方案:
在用sql语句建表的时候加入 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 即可
下面是我的建表语句:
CREATE TABLE `stat_day_exception_201807` (
`ng_id` bigint(20) NOT NULL AUTO_INCREMENT,
`ng_report_id` bigint(20) DEFAULT NULL,
`nt_type` int(11) NOT NULL,
`sz_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`sz_reason` text COLLATE utf8_unicode_ci,
`bt_charge` int(11) DEFAULT '0',
`ts_begin` datetime DEFAULT NULL,
`ts_end` datetime DEFAULT NULL,
`bt_attendance` int(11) DEFAULT '0',
`nt_count` decimal(10,4) NOT NULL DEFAULT '0.0000',
`nt_minutes` int(11) DEFAULT '0',
`sz_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`ng_user_id` bigint(20) DEFAULT NULL,
`dt_date` datetime DEFAULT NULL,
PRIMARY KEY (`ng_id`),
KEY `I_stat_day_exception_sys_user` (`ng_user_id`),
KEY `I_stat_day_exception_day` (`dt_date`)
) ENGINE=InnoDB AUTO_INCREMENT=1701 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
MySQL数据库插入中文时出现Incorrect string value: '\xE6\x97\xB7\xE5\x85\xA8' for column 'sz_name' at row 1的更多相关文章
- Mysql新建表,插入中文时报错“Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column”问题
有时候我们在往数据库中输入信息时,如果输入的内容是中文,会报错“Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column”. 例如: ...
- mysql 5.5及以前版本的编码问题“Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1”
遇到这个问题,所有的编码都设为utf8了,还是没有用,各种乱码,后来发现这是mysql自己的问题,它在5.5及之前的版本只支持3字节的utf8编码,出现4字节的utf编码时出现错误,参考: http: ...
- 向 mysql 插入汉字时报错 Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for col....
Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1 该情况一般是由数据库设计时的编 ...
- > 1366 - Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95...' for column 'description' at row 1 字符串格式错误
mysql 执行insert时报错 > 1366 - Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95...' for column 'desc ...
- django 连接MYSQL时,数据迁移时报:django.db.utils.InternalError: (1366, "Incorrect string value: '\\xE9\\x97\\xAE\\xE9\\xA2\\x98' for column 'name' at row 5")
django 连接MYSQL时,数据迁移时报:django.db.utils.InternalError: (1366, "Incorrect string value: '\\xE9\\x ...
- sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xB1\\x89\\xE8\\xAF\\xAD...' for column 'className' at row 1") [SQL: INSERT INTO classmessage (`classId
sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE ...
- mysql 插入中文字段报错 "Incorrect string value: '\\xE6\\xB5\\x8B\\xE8\\xAF\\x95...' for column 'title' at row 1"
1. 查看一个 database 或一个 table 的编码show create database mytestdb;show create table testapp_article; mysql ...
- MySQL数据库报错 > 1366 - Incorrect string value: ‘\xE6\xB1\x9F\xE6\x96\x87‘ for column ‘Teacher‘ at row 1
数据库报错这个多半是数据库在创建的时候没有选择字符编码,导致输入中文的时候出现报错. > 1366 - Incorrect string value: '\xE6\xB1\x9F\xE6\x96 ...
- [mysql] Incorrect string value: '\xE4\xBC\x9A\xE5\x91\x98' for column 'name' at row 1
数据库字符集错误, 修改为UTF8/utf8mb4字符集即可.
随机推荐
- [redis]redis-cluster的使用
1.为集群添加一个主节点 首先准备一个全新的redis文件夹,这里我们叫做为7007 [root@CentOS7 redis-cluster]# ls [root@CentOS7 redis-clus ...
- 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别(转)
因CooCox用户数及影响力越来越大,CooCox团队也逐渐提高了对软件及代码协议的重视.在收集整理的过程中,一些归纳好的信息和大家分享一下.首先借用有心人士的一张相当直观清晰的图来划分各种协议:开源 ...
- eclipse导入tomcat
官网下载tomcat压缩包 官网:http://tomcat.apache.org/ tomcat8:链接:http://pan.baidu.com/s/1kVHAEoR 密码:kyt8 tomcat ...
- python 日志模块工具类
#!/usr/bin/env python # -*- coding: utf-8 -*- import logging # logName 日志中的某个格式化的字段名,logFile生成的日志文件名 ...
- webrequest、httpwebrequest、webclient、HttpClient 四个类的区别
一.在 framework 开发环境下: webrequest.httpwebreques 都是基于Windows Api 进行包装, webclient 是基于webrequest 进行包装:(经 ...
- SQL Server 根据关键字和结束符提取字符串子串
/* @info-待截取的字符串 @indexStr-截取子串的起始字符串 @split-截取子串的结束符号 列入依次传入 胸片:正常.心电图:异常,需要注意.血常规检查:正常. 心电图 '.' 返回 ...
- WinForm中的多线程
使用BeginInvoke或Invoke 作用 在自己创建的非UI线程中,进行UI操作,比如更新UI上控件的状态. Windows 窗体中的控件被绑定到特定的线程,不具备线程安全性.因此,如果从另一个 ...
- 入门训练 Fibonacci数列 (水题)
入门训练 Fibonacci数列 时间限制:1.0s 内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n ...
- shell传参给matlab问题解决办法
之前需要通过shell脚本传参给matlab程序,但是遇到一些问题,现将我遇到的问题分享出来,给遇到同样问题的人一些借鉴. shell部分脚本Execl.sh: /usr/bin/python /ho ...
- scrapy 爬取天猫商品信息
spider # -*- coding: utf-8 -*- from urllib.parse import urlencode import requests import scrapy impo ...