Mysql error: Warning: #1366 Incorrect string value: the error is mainly caused by encoding problems. For example, if your gb2312 encoding contains traditional Chinese characters, this type of error will be prompted, therefore, this problem is caused by the encoding range.
I use mysql to record syslog-ng log information, and INSERT the log into MYSQL after decomposition. The INSERT statement is as follows:
Insert into logs (host, facility, priority, level, tag, datetime, program, msg)
VALUES ('auth', 'daemon', 'notice ', 'notice', '1d ', '2017-07-30 12:24:12', 'smbd ', 'smbd [45997]: xxxx opened file Public/pub/green light forest DVD13.rmvb read = Yes write = No (numopen = 14 )')
The following warning appears during the Insert Process:
Warning (Code 1366): Incorrect string value: 'xc2xccxb9xe2xc9xad... 'for column 'msg' at row 1
View the inserted data table. In the msg field, only the part before the Chinese character "Green Forest" is inserted, and the content is truncated. The content of the inserted text section msg is as follows:
Smbd [45997]: xxxx opened file Public/pub/
In fact, this encoding problem occurs because the occasional colleague sets GB2312 encoding. When some special characters are involved, the system will return an error and change it to "? .
Mysql error: Warning: #1366 Incorrect string value: solution:
It is easy to change the original encoding gb2312 to gbk encoding or utf8 encoding.
Attached: GB2312 and GBK encoding differences.
GB2312 is a Chinese character encoding set in simplified Chinese. GBK is an extension of GB2312. In addition to compatibility with GB2312, it can also display Traditional Chinese and Japanese Kana.
Experience
You can select the utf8 character set or modify the mysql database table, database field, or dataset to uft8.