SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,COERCIBLE) for operation 'like' 。。。
SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,COERCIBLE) for operation 'like'
这个问题是说:查询的表字符集与当前链接DB设置的字符集不一致
发现问题
① 检查链接DB设置的字符集
‘mysql’ => [ ‘driver’ => ‘mysql’, ‘host’ => env(‘DB_HOST’, ‘localhost’), ‘database’ => env(‘DB_DATABASE’, ‘forge’), ‘username’ => env(‘DB_USERNAME’, ‘forge’), ‘password’ => env(‘DB_PASSWORD’, ”), ‘charset’ => ‘utf8mb4’, ‘collation’ => ‘utf8mb4_unicode_ci’, ‘prefix’ => ”, ‘strict’ => false, ],
② 查看查询表及字段的字符集
mysql > SHOW CREATE TABLE table_name;
OR 或者
mysql > SHOW FULL Columns FROM table_name;
③ 比对链接库设置的字符集 与 表及字段 的字符集是否一致
问题解决方案:
①更改链接库字符集
②更改库、表及字段字符集
mysql > ALTER TABLE table_name MODIFY <字段><类型> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
岁月不长,不要期待来日方长