关于字符编码的问题,真心求解。
数据库
show create database game2 \G
Database: game2
Create Database: CREATE DATABASE `game2` /*!40100 DEFAULT CHARACTER SET utf8 */
表
show create table test \G
Table: test
Create Table: CREATE TABLE `test` (
   `name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
当前环境字符编码
show variables like 'character%';
| 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  |
上面是我当前环境的说明,不知道是否还有缺漏之处。
我的问题很简单,就是插入特殊字符,始终插入不进去,如下语句:
insert into test(name) values('');
执行后总是报如下错误:
ERROR 1366 (HY000): Incorrect string value: '\xA7\xCD' for column 'name' at row1
说明:我把上面的utf8全改成gbk,就可以插入,但是我想知道为什么用utf8反而不行。
------解决方案--------------------确实搞不懂
------解决方案--------------------set names 'gbk';
insert into test(name) values('');
------解决方案--------------------http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
------解决方案--------------------set names 'gbk';
------解决方案--------------------可以插入啊
------解决方案--------------------不知道你這什麼字符,感覺像全角打出來的空格,但是拷貝到數據庫那又是亂碼。。