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 'collation_%';

  mysql> show variables like 'character_set_%';

  看到编码为:latin1

  便尝试使用set命令修改:set GLOBAL Variable_name=utf8_general_ci;     set GLOBAL Variable_name=utf8; 

  结果在执行存储过程中:call xx_ya_stats_xx_daily(2018-05-18,3); 仍然报错:Illegal mix of collations for operation 'concat'

  最后再查看数据库的编码,自动恢复为latin1

3.个人结论:mysql在初始化时使用latin1字符编码,导致了里面的库表数据都是latin1字符编码,虽然改了全局的编码,但库表数据编码还是没有改到,导致失败。

4.最终解决办法:把数据库备份导出,重新初始化mysql实例,再导入数据,恢复正常。

5.步骤:

  导出:mysqldump -uroot -h'127.0.0.1' -P3306 -pxxx-E -R  db_name > db_name.sql

  修改sql:cat db_name.sql | grep -v "ALTER DATABASE \`db_name\` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;" > db_name_new.sql

  初始化同样的新实例:mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=xxxxx

  设置密码:mysql> grant all privileges on *.* to 'root'@'%' IDENTIFIED BY 'xxxx';

       mysql> flush privileges;

  修改密码:mysqladmin -h127.0.0.1 -uroot -p --port=3336 password "new_passwd"

  开启事件:SET GLOBAL event_scheduler = ON;
  查看事件是否开启:mysql> show variables like 'event_scheduler';

  创建数据库并指定字符编码:mysql> CREATE database db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  导入数据库:mysql -uroot -h'127.0.0.1' -P3306 -pxxxx db_name < db_name_new.sql

  测试:call xx_ya_stats_xxxx_daily(2018-05-18,3);

  查看编码:

    mysql> show variables like 'collation_%';

    mysql> show variables like 'character_set_%';

mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat'的更多相关文章

  1. Illegal mix of collations for operation 'concat'

    在t_employee表中,练习使用concat函数连接字符串时, mysql> select concat('工号为:',fnumber,'的员工的幸福指数:',fsalary/(fage-2 ...

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

    在使用concat连接字符串时出现错误:MySQL Error: Illegal mix of collations for operation 'concat' 原因:字段操作默认为UTF8的编码, ...

  3. Illegal mix of collations for operation 'like' while searching with Ignited-Datatables

    Stack Overflow Questions Developer Jobs Tags Users   Log In Sign Up Join Stack Overflow to learn, sh ...

  4. myslq数据库用union all查询出现 #1271 - Illegal mix of collations for operation 'UNION'

    出现 #1271 - Illegal mix of collations for operation 'UNION' 的原因是两个字符编码不匹配造成的. 我遇到的是  utf8_general_ci ...

  5. mysql 客户端连接报错Illegal mix of collations for operation

    服务端用的是utf-8,客户端工具打开表和视图是会报Illegal mix of collations for operation错误,经排查,可以采用以下语句解决 SET character_set ...

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

    内容来自博客:https://www.cnblogs.com/install/p/4417527.html MySQL Illegal mix of collations for operation ...

  7. mysql5.5修改字符编码

    因为mysql版本问题,网上各种修改编码的方法都不行,最后找到下面这条,终于解决! [mysqld]下添加: character-set-server=utf8 collation-server=ut ...

  8. mysql提示:Illegal mix of collations for operation ‘UNION’

    http://www.111cn.net/database/mysql/56096.htm show variables like "%char%"; show variables ...

  9. 有关mysql的utf8和utf8mb4,以及Illegal mix of collations for operation 'like'

    参考以下几个帖子: https://www.cnblogs.com/install/p/4417527.html https://blog.csdn.net/Yetmoon/article/detai ...

随机推荐

  1. windows运行打开服务命令

    1. gpedit.msc-----组策略    2. sndrec32-------录音机   3. Nslookup-------IP地址侦测器   4. explorer-------打开资源管 ...

  2. magento的常用调用

    1,CMS调用网站的Url <a href="{{store direct_url="about-us"}}">About Us</a> ...

  3. CodeForces - 1087F:Rock-Paper-Scissors Champion(set&数状数组)

    n players are going to play a rock-paper-scissors tournament. As you probably know, in a one-on-one ...

  4. 20155338 2016-2017-2 《Java程序设计》第8周学习总结

    20155338 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 一.日志 API简介 java++.util.logging包提供了日志功能相关类与接口,不 ...

  5. LOJ2542. 「PKUWC2018」随机游走【概率期望DP+Min-Max容斥(最值反演)】

    题面 思路 我们可以把到每个点的期望步数算出来取max?但是直接算显然是不行的 那就可以用Min-Max来容斥一下 设\(g_{s}\)是从x到s中任意一个点的最小步数 设\(f_{s}\)是从x到s ...

  6. 纯CSS绘制三角形(各种角度)类似于使用字符画法,根据位移不同,也可以使用两个元素画出三角边框

    我们的网页因为 CSS 而呈现千变万化的风格.这一看似简单的样式语言在使用中非常灵活,只要你发挥创意就能实现很多比人想象不到的效果.特别是随着 CSS3 的广泛使用,更多新奇的 CSS 作品涌现出来. ...

  7. Tomcat:Several ports are already in use问题

    Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The ...

  8. 剑指offer-第一个只出现一次的字符-字符串和数组

    用到的算法都是像冒泡排序,直接选择排序,插入排序 每趟进行处理,这个趟是没有什么实际意义的 变量j一次从头走到尾进行一次循环枚举遍历扫描 一.题目:第一个只出现一次的字符 题目:在字符串中找出第一个只 ...

  9. 微软通过.NET Native为Windows Store应用提速

    .NET Native是微软的一次尝试,旨在降低Windows Store应用的启动时间和内存占用. 自从去年11月份,有人发现Windows Store应用的启动速度有了大幅提高后,对该项目的猜测就 ...

  10. Ritchie Lawrence 批处理函数库中英文版

    可以到这个网址去看看,如果你是注册用户,还可以下载到bat的很多函数库,具体地址如下: http://www.bathome.net/viewthread.php?tid=3056&extra ...