日期:2014-05-16  浏览次数:20789 次

插入中文报错:incorrect string value
在插入中文时报“incorrect string value”,下面是编码配置的情况:

mysql> show variables like '%char%';
+--------------------------+-------------------------------------+
| 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 | D:\MySQL Server 5.5\share\charsets\ |
+--------------------------+-------------------------------------+

mysql> show create database mydb;
+-----------+--------------------------------+
| Database | Create Database |
+-----------+--------------------------------+
| mydb | CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+-----------+--------------------------------+
1 row in set (0.00 sec)


mysql> show create table test;
+-------+-------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------+
| test | CREATE TABLE `test` (
  `s` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------+

请问该如何处理,谢谢!

------解决方案--------------------
set names utf8再插入
------解决方案--------------------
set names 'gbk';
insert into test values ('请问');
select * from test;

设置字符集后再试。

http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码