MySQL學習筆記04 插入中文時出現ERROR 1366 (HY000)


1 環境: MySQL Server 6.0  命令行工具

2 問題 :  插入中文字符數據出現如下錯誤:

ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1

3 當時環境:

mysql> insert into user(id  , username , birthday, sex, address) values('2' ,  '
李四' , '1980 12-31' ,  'male' , 'beijing');
ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern
ame' at row 1
mysql> select * from user;
Empty set (0.00 sec)

mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into user(id  , username , birthday, sex, address) values('2' ,  '
李四' , '1980 12-31' ,  'male' , 'beijing');
Query OK, 1 row affected (0.10 sec)

mysql> select * from user;
+----+----------+------------+------+---------+
| id | username | birthday   | sex  | address |
+----+----------+------------+------+---------+
| 2  | 李四         | 1980 12-31 | male | beijing |
+----+----------+------------+------+---------+
1 row in set (0.00 sec)

4 總結

當出現亂碼,就是編碼的問題,可以嘗試設置數據庫的編碼(set nams gbk)。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM