当我们在向mysql中的表中插入数据报了这个一个错误
1366 - Incorrect string value: 'xE4xBAxBAxE4xBAx8B...' for column 'dname' at row 1
mysql> use test; Database changed mysql> INSERT INTO department(did,dname) VALUES(1,'人事部'); 1366 - Incorrect string value: 'xE4xBAxBAxE4xBAx8B...' for column 'dname' at row 1 mysql> INSERT INTO department(did,dname) VALUES(1,'人事部'); 1366 - Incorrect string value: 'xE4xBAxBAxE4xBAx8B...' for column 'dname' at row 1
是因为在建表的时候没有使用中文编码,所有存不了相应的中文数据
我们把原来的表删除。重新建表
mysql> CREATE TABLE department( did INT(4) PRIMARY KEY, dname VARCHAR(36) NOT NULL ) default charset=utf8 ; Query OK, 0 rows affected (0.02 sec) mysql> CREATE TABLE employee (id INT(4) PRIMARY KEY, NAME VARCHAR(36) NOT NULL, age INT(2) NOT NULL, did INT(4) )default charset=utf8 ; Query OK, 0 rows affected (0.02 sec) mysql> INSERT INTO department(did,dname) VALUES(1,'人事部'); Query OK, 1 row affected (0.01 sec) mysql> INSERT INTO department(did,dname) VALUES(2,'院校产品部'); INSERT INTO department(did,dname) VALUES(3,'咨询部'); Query OK, 1 row affected (0.00 sec) Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO employee(id,NAME,age,did) VALUES(1,'张三',20,1); INSERT INTO employee(id,NAME,age,did) VALUES(2,'李四',35,2); INSERT INTO employee(id,NAME,age,did) VALUES(3,'王五',19,3); Query OK, 1 row affected (0.01 sec) Query OK, 1 row affected (0.00 sec) Query OK, 1 row affected (0.00 sec)
这样问题就解决了!!