本文主要是介绍mysql中文异常,Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天在操作mysql的时候,输入中文的时候出现异常,Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 。
上网查了下原因是因为表的字符集不一致。
SHOW VARIABLES LIKE 'character_set_%'; 查看一下 显示
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8|
| character_set_connection | utf8|
| character_set_database | latin1 |
| character_set_results | utf8|
| character_set_server | latin1 |
| character_set_system | utf8 |
再用 SHOW VARIABLES LIKE 'collation_%'; 查看一下 显示
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
好了,看出问题在哪里了
set character_set_database =utf8;set character_set_results =utf8;set character_set_server =utf8;set character_set_system =utf8; --此处utf-8也可以然后执行:SET collation_server = utf8_general_ciSET collation_database = utf8_general_ci
重启一下,式了下 还是不行。
再看
show full columns from 表名;
发现字段字符集还是不正确,这个时候,你有两种选择,如果表里面还没有数据,就drop掉,重新create一张表,
或者设置字段的字符集。
ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
再去试试看。。终于可以了。。
这篇关于mysql中文异常,Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!