蛋疼的MySQL 编码问题

kong_resty 发布于 2012/03/31 16:10
阅读 331
收藏 0
 mysql> use test;
Database changed
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       | C:\Program Files\MySQL\MySQL Server 5.5\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| dept           |
| emp            |
+----------------+
2 rows in set (0.00 sec)

mysql> desc emp;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| ename     | varchar(32)  | YES  |     | NULL    |                |
| sal       | decimal(8,2) | YES  |     | NULL    |                |
| hire_date | date         | YES  |     | NULL    |                |
| deptno    | int(11)      | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> show create table emp;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------+
| Table | Create Table


                                           |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------+
| emp   | CREATE TABLE `emp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ename` varchar(32) DEFAULT NULL,
  `sal` decimal(8,2) DEFAULT NULL,
  `hire_date` date DEFAULT NULL,
  `deptno` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------+
1 row in set (0.00 sec)

mysql> insert into emp(ename, sal, hire_date)
    ->  values('张三',1000, '2009-2-1');
ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'ename
' at row 1
mysql>

 

求指教啊  我编码都设置成utf-8了的啊  为什么还是不行

 

加载中
0
kong_resty
kong_resty

我设置成如下 就能插入中文了:

        mysql> use test;
Database changed
mysql> select * from emp;
+----+-------+---------+------------+--------+
| id | ename | sal     | hire_date  | deptno |
+----+-------+---------+------------+--------+
|  1 | 章    | 2000.00 | 2009-03-13 |   NULL |
+----+-------+---------+------------+--------+
1 row in set (0.00 sec)

mysql> show variables like '%char%';
+--------------------------+----------------------------------------------------
-----+
| 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       | C:\Program Files\MySQL\MySQL Server 5.5\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)

mysql>

0
彷徨的看着你
彷徨的看着你
set names 'utf8';
返回顶部
顶部