0

I'm trying to insert this text via SQL query

INSERT INTO `tbl_instructions` (`No`, `Language`, `Text`) VALUES
('Introduction','HU','Kérdőív - ""Ismerd meg Önmagad!""  Ahogy az ókori görögök mondták: ""Ismerd meg Önmagad!"" - Ez a célja ennek a személyiségtesztnek is. Ez a teszt egy negyedórás szemtől szembeni beszélgetésnek felel meg.  A teszt kitöltése nagyjából fél órát igényel. Közben megszakíthatja az internetkapcsolatot, elég a teszt elküldéséhez visszaállítania azt.  Jó szórakozást kívánunk a teszthez, természetesen az adatait bizalmasan kezeljük és nem osztjuk meg senkivel. Ezt garantálja  Andreas és Telse Gross');

and I'm getting:

#1366 - Incorrect string value: '\xC5\x91\xC3\xADv ...' for column my_database.tbl_instructions.Text at row 1

I tried utf8_unicode_ci and UTf8mb4_unicode_ci and I'm still getting the same error.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Dev Dev
  • 314
  • 4
  • 17
  • What's the collation of the table, and of the target column? – Martin May 20 '21 at 09:45
  • "I tried utf8_unicode_ci and UTf8mb4_unicode_ci" Those are the collations I tried. and for the Text column is TEXT the rest is varchar 255 – Dev Dev May 20 '21 at 09:48
  • I've changed the tags to reflect the fact you are using MariaDB 10.2 instead of MySql. It's better to always tag the correct RDBMS when posting because it often does affect the answer – Martin May 20 '21 at 10:12

1 Answers1

2

This is likely to be a collation issue with the Text column in the target table.

Consider the following, which uses a Text column created with the latin1_general_ci collation:

CREATE TEMPORARY TABLE `tbl_instructions` (`Text` VARCHAR(1000) COLLATE latin1_general_ci);

INSERT INTO `tbl_instructions` (`Text`) VALUES ('Kérdőív - ""Ismerd meg Önmagad!""  Ahogy az ókori görögök mondták: ""Ismerd meg Önmagad!"" - Ez a célja ennek a személyiségtesztnek is. Ez a teszt egy negyedórás szemtől szembeni beszélgetésnek felel meg.  A teszt kitöltése nagyjából fél órát igényel. Közben megszakíthatja az internetkapcsolatot, elég a teszt elküldéséhez visszaállítania azt.  Jó szórakozást kívánunk a teszthez, természetesen az adatait bizalmasan kezeljük és nem osztjuk meg senkivel. Ezt garantálja  Andreas és Telse Gross');

This produces the following error:

Error Code: 1366. Incorrect string value: '\xC5\x91\xC3\xADv ...' for column 'Text' at row 1

Now consider the following, that uses utf8mb4_0900_ai_ci:

CREATE TEMPORARY TABLE `tbl_instructions` (`Text` VARCHAR(1000) COLLATE utf8mb4_0900_ai_ci);

INSERT INTO `tbl_instructions` (`Text`) VALUES ('Kérdőív - ""Ismerd meg Önmagad!""  Ahogy az ókori görögök mondták: ""Ismerd meg Önmagad!"" - Ez a célja ennek a személyiségtesztnek is. Ez a teszt egy negyedórás szemtől szembeni beszélgetésnek felel meg.  A teszt kitöltése nagyjából fél órát igényel. Közben megszakíthatja az internetkapcsolatot, elég a teszt elküldéséhez visszaállítania azt.  Jó szórakozást kívánunk a teszthez, természetesen az adatait bizalmasan kezeljük és nem osztjuk meg senkivel. Ezt garantálja  Andreas és Telse Gross');

This runs successfully.

Simply specifying the collation on INSERT is not good enough - if the target column is an incompatible collation then you will get the error message you are seeing.

The table should be modified to be the correct collation - I am not suggesting it should be utf8mb4_0900_ai_ci. Use the collation that is appropriate for your needs (for example, latin2_general_ci also works for your character set).

Update following OP changing RDBMS to MariaDB instead of MySQL

Following your comment about using MariaDB instead of MySQL, you could use utf8mb4_general_ci which is available in MariaDB 10.2.

Here's a working fiddle for MariaDB 10.3 showing it working using that collation.

Martin
  • 16,093
  • 1
  • 29
  • 48
  • My database is 10.2.38-MariaDB - MariaDB Server. utf8mb4_0900_ai_ci does not exist as collation type when I want to edit the table structure. I tested latin2_general_ci and it is not working, it gives the same error. – Dev Dev May 20 '21 at 10:03
  • How did you test it? You must change the collation of the table column, not in the `INSERT` statement. In MariaDB 10.2 I think you can use `utf8mb4_general_ci`. – Martin May 20 '21 at 10:10
  • @DevDev Btw you didn't tag MariaDB on the question - you tagged MySQL. Would have been better to know up front the actual RDBMS you were using – Martin May 20 '21 at 10:11
  • I'm very sorry, I misunderstood you. I changed the table collation not each column collation. Now it is working fine with utf8mb4_general_ci and for MySQL Vs Maria DB I though they behave the same :) – Dev Dev May 20 '21 at 10:16
  • @DevDev No problem - glad we got it resolved in the end. MySQL and MariaDB share a history but as you have seen with the collation names, there is a difference sometimes – Martin May 20 '21 at 10:21