3

I have MySQL table with column and its properties:

name:               message
datatype:           varchar(300)
default/expression: utf8

I trying to insert new data in table that contain text in Cyrillic.

Here's my sql query:

INSERT INTO db.log (id, info_id, user_id, timestamp, operation, message) 
  VALUES ('792','575', '35','2016-12-20 12:09:45','add',
  'user@gmail.com created new line тест ')

I got the exception:

1 row(s) affected, 1 warning(s): 1366 Incorrect string value: '\xD1\x82\xD0\xB5\xD1\x81...' for column 'message'

What can I do to resolve the exception?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Lena
  • 99
  • 4
  • 14
  • 3
    Please provide the relevant code . – Arnaud Dec 20 '16 at 10:37
  • string value is hexadecimal escapes, and the string probably is submitted by the web-page - looks like charset header got missing during submission – Vladimir Dec 20 '16 at 11:04
  • @ Berger, here's my sql request: 13:05:52 INSERT INTO db.log (id, info_id, user_id, timestamp, operation, message) VALUES ('792','575', '35','2016-12-20 12:09:45','add','user@gmail.com created new line тест ') and that gives me exception: 1 row(s) affected, 1 warning(s): 1366 Incorrect string value: '\xD1\x82\xD0\xB5\xD1\x81...' for column 'message' at row 1 0.073 sec – Lena Dec 20 '16 at 11:12
  • @Lena Next time it is better to edit post – Alex K Dec 22 '16 at 14:20

1 Answers1

6

Seems that the default character set for your database is likely Latin or other, thou it doesn't store Cyrillic.
Use ALTER DATABASE and ALTER TABLE commands to make sure of correct character set:

ALTER DATABASE your_DB_name CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

See more info on your issue here: How to convert an entire MySQL database characterset and collation to UTF-8?

Community
  • 1
  • 1
e5d3e1
  • 101
  • 3