MySQL字符编码问题,Incorrect string value
MySQL上插入汉字时报错例如以下。详细见后面分析。
Incorrect string value: '\xD0\xC2\xC8A\xBEW' for column 'ctnr' at row 1
MySQL字符集相关參数:
character_set_server : 服务器字符集
collation_server : 服务器校对规则
character_set_database : 默认数据库的字符集
collation_database : 默认数据库的校对规则
character_set_client:server使用该变量取得链接中客户端的字符集
character_set_connection:server将客户端的query从character_set_client转换到该变量指定的字符集。
character_set_results:server发送结果集或返回错误信息到client之前应该转换为该变量指定的字符集
有两个语句能够设置连接字符集。例如以下:
A
SET NAMES 'charset_name' 相当于以下三句:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET character_set_connection = x; #这个也设置了collation_connection的默认值x
B
SET CHARACTER SET charset_name 相当于以下三句:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET collation_connection = @@collation_database;
character_set_results为NULL时,server对返回结果集不做不论什么转换
mysql> SET character_set_results = NULL;
由于字符集编码引起的问题在pg上报的错是:invalid byte sequence for encoding "UTF8"。详细见參考
http://blog.csdn.net/beiigang/article/details/39582583
MySQL上字符集编码引起的问题报:Incorrect string value,详细见以下实验:
1
mysql> show variables like '%character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
2
mysql> create table tb_tt (id int, ctnr varchar(60));
Query OK, 0 rows affected (0.06 sec)
3
mysql> show create table tb_tt;
+-------+-----------------------------------------------------------------------
-----------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
-----------------------------------------------------+
| tb_tt | CREATE TABLE `tb_tt` (
`id` int(11) DEFAULT NULL,
`ctnr` varchar(60) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------
-----------------------------------------------------+
1 row in set (0.00 sec)
4
mysql> insert into tb_tt(id,ctnr) values(1,'新華網');
Query OK, 1 row affected (0.02 sec)
5
mysql> select * from tb_tt;
+------+--------+
| id | ctnr |
+------+--------+
| 1 | 新華網 |
+------+--------+
1 row in set (0.02 sec)
6
mysql> set names 'UTF8';
Query OK, 0 rows affected (0.00 sec)
7
mysql> show variables like '%character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
8
mysql> insert into tb_tt(id,ctnr) values(2,'新華網');
ERROR 1366 (HY000): Incorrect string value: '\xD0\xC2\xC8A\xBEW' for column 'ctnr' at row 1
9
If you change the default character set or collation for a database,
stored routines that use the database defaults must be dropped and
recreated so that they use the new defaults. (In a stored routine,
variables with character data types use the database defaults if the
character set or collation are not specified explicitly. See [HELP
CREATE PROCEDURE].)
參考:
http://dev.mysql.com/doc/refman/5.5/en/globalization.html
http://dev.mysql.com/doc/refman/5.5/en/alter-database.html
-----------------
转载请著明出处:
blog.csdn.net/beiigang
MySQL字符编码问题,Incorrect string value的更多相关文章
- Linux MySQl 5.7.17 MySQL ERROR 1366(HY000):Incorrect string value 解决方法
MySQL ERROR 1366(HY000):Incorrect string value,在往数据库中插入中文的时候会出现. 这也就是编码问题,网上大部分都是说设置下配置文件中的设置,而可悲的是在 ...
- mysql导入数据库出现:Incorrect string value: '\xE7\x82\xB9\xE9\x92\x9F' for column 'chinese' at row 1
mysql导入数据库出现:Incorrect string value: '\xE7\x82\xB9\xE9\x92\x9F' for column 'chinese' at row 1 使用 sho ...
- 修改数据库mysql字符编码为UTF8
Mysql数据库是一个开源的数据库,应用非常广泛.以下是修改mysql数据库的字符编码的操作过程. 步骤1:查看当前的字符编码方法 mysql> show variables like'char ...
- linux mysql字符编码问题
发布:thatboy 来源:脚本学堂 [大 中 小] 本文介绍下,linux环境中mysql字符编码问题的解决办法,有遇到mysql编码问题的朋友,可以参考下本文的介绍,希望对你有一定的帮 ...
- 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 ...
- mysql 彻底解决:Incorrect string value: '\xF0\x9F\x98\xAD",...' for column 'commentContent' at row 1
彻底解决:Incorrect string value: '\xF0\x9F\x98\xAD",...' for column 'commentContent' at row 1 今天在爬取 ...
- MySQL ERROR 1366(HY000) Incorrect string value
有以下两张表: mysql> show tables; +---------------+ | Tables_in_old | +---------------+ | book | | pres ...
- mysql 插入汉字 异常 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name'
今天使用mysql出现 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name' 异常 通过查找问题,发现是字段编码不支 ...
- php 解决MySQL插入数据出现 Incorrect string value: '\xF0\x9F\x92\x8BTi...'错误
在项目中向MySQL插入数据时.发现数据插入不完整,通过调试,发现插入语句也没什么特殊的错误. 可是就是差不进去,于是就打开mysqli错误的调试 $ret = mysqli_query($this- ...
随机推荐
- Use PSO to find minimum in OpenCASCADE
Use PSO to find minimum in OpenCASCADE eryar@163.com Abstract. Starting from OCCT6.8.0 will include ...
- C++ 递归位置排列算法及其应用
废话不多说,我们先看一下位置排序的算法: #include <iostream> using namespace std; int n = 0; int m = 2; int l = 0; ...
- es64 const
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ 2455 二分+网络流
题意: 思路: 莫名其妙TLE 啊woc我A了一坨题的网络流模板有问题 !!!! 在常数上会慢 (一个等于号 啊啊啊) 改了所有网络流有关的文章- .... //By SiriusRen #inclu ...
- vue脚手架3.0的搭建
一.安装node 打开cmd输入node -v查看是否安装成功 显示node版本号表示安装成功,显示‘node’不是内部或外部命令表示未安装node.node安装地址:http://nodejs.cn ...
- eclipse- 智能提示设置
最近自己ubuntu 下的eclipse没办法只能提示了.后来在网上查了方法,完美解决了问题 1.java代码编辑的时候不提示 具体如下 Windows→Preferences→Java→Editor ...
- Java学习笔记八
IO流:就是input/output输入/输出流. 一.字节流操作文件的便捷类:FileWriter和FileReader import java.io.FileWriter; import java ...
- MSSQL相关用法
一.分页查询 方式一(row_number): SELECT TOP pageSize * FROM (SELECT row_number() OVER (ORDER BY orderColumn) ...
- OR1200指令Cache使用举例
下面内容摘自<步步惊芯--软核处理器内部设计分析>一书 12.4 ICache中的特殊寄存器 通过ICache的接口可知其具有特殊寄存器,而且是不可读的特殊寄存器,OR1200处理器中IC ...
- Windows Server 2016 上配置 APACHE+SSL+PHP+perl
Windows Server 2016 上配置 APACHE+SSL+PHP+perl 安装环境 谷歌云实例 Windows Server 2016 Apache Apache/2.4.25 (win ...