1. Specific scenarios
The two tables are:
CREATE TABLE `tb_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户编号(自增字段)',
`userName` varchar(32) NOT NULL DEFAULT '' COMMENT '用户昵称',
# ...
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8 COMMENT='用户表';
CREATE TABLE `tb_sms_message` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`tel` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '手机号',
# ...
PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8;
Error Message:
Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation ‘=’
2.Find SQL
SELECT * FROM `tb_sms_message`
where tel not IN (select userName from tb_user);
3. Cause analysis
The collates of the two associated fields are inconsistent and cannot be directly associated
Here, we can convert the proofreading set of the field to consistent:
CONVERT(tel USING utf8) COLLATE utf8_general_ci
Modified SQL:
SELECT * FROM `tb_sms_message`
where CONVERT(tel USING utf8) COLLATE utf8_general_ci not IN (select userName from tb_user);
Similar Posts:
- mysql: [Err] 1075 – Incorrect table definition; there can be only one auto column and it must be d…
- MySQL timestamp set default value error Invalid default value reason and solution
- When mysql creates a table, set timestamp DEFAULT NULL error 1067-Invalid default value for’updated_at’
- [Err] 1214 – The used table type doesn’t support FULLTEXT indexes
- Database upgrade from Zabbix 5.0.15 to Zabbix 5.2.7 failed
- Failed to read auto-increment value from storage
- MYSQL ERROR 1005 (HY000): Can’t create table [How to Solve]
- SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”
- [Solved] MYSQL5.6 Error: ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.
- MySQL Error Number 1005 Can’t create table (Errno:150)