mysql general error,mysql General error: 1267 Illegal mix of collations错误​

在项目迁移之后一个视图的访问出现了问题,报了mysql的1267错误,具体报错信息就是

SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb4_unicode_ci,COERCIBLE) and (utf8mb4_general_ci,COERCIBLE) for operation '='

SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb4_unicode_ci,COERCIBLE) and (utf8mb4_general_ci,COERCIBLE) for operation '='

查看了构建的视图

5fbcceccbef21.png

发现type的字符集和user_name不一致,貌似是字符集有问题,尝试修改type的字符集

我的视图

CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`%` SQL SECURITY DEFINER VIEW `goods_in_out_view` AS SELECT

`goods_in`.`id` AS `id`,

`goods_in`.`shop_id` AS `shop_id`,

'in' AS `type`,

`goods_in`.`goods_id` AS `goods_id`,

`goods_in`.`in_price` AS `price`,

`goods_in`.`number` AS `number`,

`goods_in`.`supplier_id` AS `supplier_id`,

0 AS `customer_id`,

`goods_in`.`user_name` AS `user_name`,

`goods_in`.`create_time` AS `create_time`,

`goods_in`.`update_time` AS `update_time`,

`goods_in`.`delete_time` AS `delete_time`

FROM

`goods_in`

WHERE

(`goods_in`.`delete_time` = 0)

UNION

SELECT

`goods_out`.`id` AS `id`,

`goods_out`.`shop_id` AS `shop_id`,

'out' AS `type`,

0 AS `goods_id`,

`goods_out`.`price` AS `price`,

`goods_out`.`number` AS `number`,

0 AS `supplier_id`,

`goods_out`.`customer_id` AS `customer_id`,

`goods_out`.`user_name` AS `user_name`,

`goods_out`.`create_time` AS `create_time`,

`goods_out`.`update_time` AS `update_time`,

`goods_out`.`delete_time` AS `A`

FROM

`goods_out`

WHERE

(`goods_out`.`delete_time` = 0)

修改后的视图

CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`%` SQL SECURITY DEFINER VIEW `goods_in_out_view` AS SELECT

`goods_in`.`id` AS `id`,

`goods_in`.`shop_id` AS `shop_id`,

convert('in' using utf8mb4) AS `type`,

`goods_in`.`goods_id` AS `goods_id`,

`goods_in`.`in_price` AS `price`,

`goods_in`.`number` AS `number`,

`goods_in`.`supplier_id` AS `supplier_id`,

0 AS `customer_id`,

`goods_in`.`user_name` AS `user_name`,

`goods_in`.`create_time` AS `create_time`,

`goods_in`.`update_time` AS `update_time`,

`goods_in`.`delete_time` AS `delete_time`

FROM

`goods_in`

WHERE

(`goods_in`.`delete_time` = 0)

UNION

SELECT

`goods_out`.`id` AS `id`,

`goods_out`.`shop_id` AS `shop_id`,

convert('out' using utf8mb4) AS `type`,

0 AS `goods_id`,

`goods_out`.`price` AS `price`,

`goods_out`.`number` AS `number`,

0 AS `supplier_id`,

`goods_out`.`customer_id` AS `customer_id`,

`goods_out`.`user_name` AS `user_name`,

`goods_out`.`create_time` AS `create_time`,

`goods_out`.`update_time` AS `update_time`,

`goods_out`.`delete_time` AS `A`

FROM

`goods_out`

WHERE

(`goods_out`.`delete_time` = 0)

这里使用convert对字符串的字符集进行了转换

convert('in' using utf8mb4) AS `type`

转换后再访问发现正常了,再去看一下视图结构

5fbcd026ae44e.png

问题解决!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值