Illegal mix of collations for operation 'concat'

在t_employee表中,练习使用concat函数连接字符串时,

mysql> select concat(‘工号为:‘,fnumber,‘的员工的幸福指数:‘,fsalary/(fage-21))
-> from t_employee;
1271 - Illegal mix of collations for operation ‘concat‘   报错

在网上查看了相关错误文章发现是字段得字符集有问题,我这里的fnumber字段的字符集是latin1,而字段操作默认为UTF8的编码。 绝对统一使用UTF-8 。

修改了字符集为utf-8后再次运行SQL命令

mysql> select concat(‘工号为:‘,fnumber,‘的员工的幸福指数:‘,fsalary/(fage-21))
-> from t_employee;
+-----------------------------------------------------------------+
| concat(‘工号为:‘,fnumber,‘的员工的幸福指数:‘,fsalary/(fage-21)) |
+-----------------------------------------------------------------+
| 工号为:dev001的员工的幸福指数:2075.000000 |
| 工号为:dev002的员工的幸福指数:328.685714 |
| 工号为:HR001的员工的幸福指数:1100.400000 |
| 工号为:HR002的员工的幸福指数:1300.090000 |
| 工号为:IT001的员工的幸福指数:557.142857 |
| 工号为:IT002的员工的幸福指数:466.666667 |
| 工号为:sales001的员工的幸福指数:2500.000000 |
| 工号为:sales002的员工的幸福指数:885.714286 |
| 工号为:sales003的员工的幸福指数:1200.000000 |
+-----------------------------------------------------------------+
9 rows in set

搜索出来的数据是正确的,没有报错。

Illegal mix of collations for operation 'concat'

时间: 2024-08-25 06:26:56

Illegal mix of collations for operation 'concat'的相关文章

MySQL Error: Illegal mix of collations for operation 'concat'

在使用concat连接字符串时出现错误:MySQL Error: Illegal mix of collations for operation 'concat' 原因:字段操作默认为UTF8的编码,应该绝对统一使用UTF-8,而创建数据库时使用了其它编码.  解决方法:在Navicat for MySQL中删除掉原来的数据库,重新新建,新建时设置字符集和排序规则为UTF-8 MySQL Error: Illegal mix of collations for operation 'concat

mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat'

mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat' 1.问题起因:搭建环境初始化mysql的时候看到mysql配置文件[cloent]下有设置编码为default-character-set = utf8,大意误以为是全局配置了,其实还需要在[mysqld]下添加character_set_server = utf8参数的 2.尝试在线处理: mysql> show variables like 'collati

MySQL SQL error: #1271 - Illegal mix of collations for operation 'UNION'

MySQL在使用UNION查询时或者创建视图时报:异常:SQL error: #1271 - Illegal mix of collations for operation 'UNION',此类问题是由于UNION Mysql的Table的时候对应的字段Collation字符序不同导致的,如下图所示: 创建视图或者查询时采用UNION ALL报异常 通过WorkBench查看相关查询的表的详细信息发现字符类型的字段的Collation不同 通过修改字段的Collation解决此类错误,或者创建字

MySQL 报错:MySQL Illegal mix of collations for operation 'like'

MySQL Illegal mix of collations for operation 'like' 在 MySQL 5.5 以上, 若字段类型 Type 是 time,date,datetime 在 select时如果使用 like '%中文%' 会出现 Illegal mix of collations for operation 'like'在编程时要对每个字段进行查找, 在执行时可能就会出现时间字段 like '%中文%' 这种语法,在旧版的 MySQL 是不会出现错误的. 升到 M

错误之Illegal mix of collations for operation 'like'

内容来自博客:https://www.cnblogs.com/install/p/4417527.html MySQL Illegal mix of collations for operation 'like'在 MySQL 5.5 以上, 若字段类型 Type 是 time,date,datetime 在 select时如果使用 like '%中文%' 会出现 Illegal mix of collations for operation 'like'在编程时要对每个字段进行查找,在执行时可

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

Error:Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gbk_chinese_ci,COERCIBLE) for operation '='Errno:1267 问题很明显,就是Mysql字符编码问题,所以主要排查问题方向应该往设置编码及用到编码的地方 这里是Mysql设置编码的常用命令,一般在链接数据时会用到: SET CHARACTER_SET_CLIENT = utf8, CHARACTER_SET_CONNECTI

mysql: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '= 的解决

昨天把mysql里所有table的varchar字段的字符集,批量换成了utf8mb4/utf8mb4_unicode_ci ,以便能保存一些emoji火星文 , 结果有一个sql语句执行时,报错如下: Illegalmixofcollations(utf8_unicode_ci,IMPLICIT)and(utf8_general_ci,IMPLICIT)foroperation '= 观察了一下,这个sql使用了一个自定义的function,这个函数的入口参数为varchar,类似如下: CR

c#程序连接mysql,报"Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='"的解决方案

=============================================== 20170607_第一次修改                       ccb_warlock =============================================== 工作关系开发一个连接mysql的c#程序,交付测试后反应在连测试环境的数据库后出现报错且数据无法获取的情况.(如下图所示) 查到了http://www.cnblogs.com/xiaochaohuashengm

日常问题记录--插入记录时报 Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误

背景: 写一个数据DB操作时,日志报Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误: 原因: 1.插入式代码中的数据类型为GBK: 2.DB建表时忘记修改默认的编码格式(默认为 Collation: latin1_swedish_ci 格式): 1.2结合之后,插入数据编码错误: 定位方法: 1.查看DB表的字段编码 show f