MySQL ERROR 1366(HY000) Incorrect string value


有以下兩張表:

mysql> show tables;
+---------------+
| Tables_in_old |
+---------------+
| book          |
| press         |
+---------------+
2 rows in set (0.00 sec)

mysql> desc book;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | int(11)     | NO   | PRI | NULL    |       |
| name     | varchar(10) | YES  | UNI | NULL    |       |
| press_id | int(11)     | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> desc press;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(10) | YES  | UNI | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

在往表里插數據時報錯了:

mysql> insert into press(name) values
    -> ('北京工業地雷出版社'),
    -> ('人民音樂不好聽出版社'),
    -> ('知識產權沒有用出版社')
    -> ;
ERROR 1366 (HY000): Incorrect string value: '\xE5\x8C\x97\xE4\xBA\xAC...' for column 'name' at row 1

不支持中文,查看下字符編碼:

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)


發現database的字符編碼是latin1,修改字符編碼:

mysql> SET CHARACTER_SET_DATABASE=utf8;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 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                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

現在看起來修改過來了,現在插入數據:

mysql> insert into press(name) values
    -> ('北京工業地雷出版社'),
    -> ('人民音樂不好聽出版社'),
    -> ('知識產權沒有用出版社')
    -> ;
ERROR 1366 (HY000): Incorrect string value: '\xE5\x8C\x97\xE4\xBA\xAC...' for column 'name' at row 1

發現還是報錯,最直接的辦法是刪庫跑路!!!!

不過需要查看當前庫的字符編碼,然后修改。


免責聲明!

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



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