报错: java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='
原因:几张表关联的时候,如果表的字符集不一致,就会出现这样的问题
几步走:
1、查看字符集配置
show VARIABLES WHERE variable_name like '%collation%'
2、看一下关联的表使用的是什么字符集:
show create table xx_table
3、修改表字符集:
alter table xx_table1 default character set utf8mb4 collate=utf8mb4_0900_ai_ci
4、修改字段的字符集:
有时候只改表的字符集是不行的,还需要改字段的字符集
ALTER TABLE xx_table2 convert to CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci
修改数据库字符集:ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...]
把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE ...]
如:ALTER TABLE logtest CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
只是修改表的默认字符集:
ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...]
如:ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)