简体   繁体   中英

MySQL illegal mix of collations for operation '=' on a simple INSERT

There is a lot of questions about collation mixup in SELECT and INSERT * SELECT statements. Mine is a simple INSERT with nothing added to it but the data.

The error spawned in the process is:

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

All field names and table names have been simplified. The query being executed is:

INSERT INTO table1 (`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`,`i`,`j`) VALUES (?,?,?,?,?,?,?,?,?,?);```

It has been prepared to receive some data that is brought in by the Java process with JDBI.

The underlying tables have nothing odd about them. Their DDLs look as follows.

CREATE TABLE `table1` (
  `a` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `b` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL,
  `c` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `d` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `e` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `f` int(11) DEFAULT NULL,
  `g` text COLLATE utf8_unicode_ci,
  `h` bigint(20) DEFAULT NULL,
  `i` bigint(20) DEFAULT NULL,
  `j` datetime DEFAULT NULL,
  `k` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`a`,`e`),
  KEY `c` (`c`,`d`),
  CONSTRAINT `fk_1` FOREIGN KEY (`a`) REFERENCES `table2` (`a2`),
  CONSTRAINT `fk_2` FOREIGN KEY (`c`, `d`) REFERENCES `table3` (`a3`, `b3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

CREATE TABLE `table2` (
  `a2` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `b2` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `c2` mediumtext COLLATE utf8_unicode_ci,
  `d2` mediumtext COLLATE utf8_unicode_ci,
  `e2` bigint(11) DEFAULT '0',
  PRIMARY KEY (`a2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

CREATE TABLE `table3` (
  `a3` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `b3` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`a3`,`b3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

As can be seen, there is absolutely nothing about the collation that I can understand. Is it possible that the data coming in from the java world is causing this? Could it be related to the current connection session variables?


UPDATE

I forgot to add the MySQL version: 5.6

I have solved this issue in my test runs moving all field collations to DEFAULT and the table collation to utf8_general_ci on table1 . However, this is an unacceptable solution to the problem and it does not come close to answering how can there be a collation mixup in a simple INSERT statement?

I found the culprit. There is a TRIGGER on this table that references another table from another schema. The conflict exists in the trigger statements which does not help that the error message makes no allusion to such fact.

That answers

how can there be a collation mixup in a simple INSERT statement?

There is a TRIGGER accompanying the INSERT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM