错误是在你的结果集中有两种字符集。
比如说你在两个表联合查询,一个表的字符集是latin1,另一个是utf8,这样在你的结果集中有两种字符集,mysql会报上面的错误。
一个表中不同的字段使用不同的字符集,也是一个道理。
用SHOW CREATE TABLE table_name;可以看出具体的字符集设置。解决方法:
将不同的字符集,转化成统一的字符集。
比如说你在两个表联合查询,一个表的字符集是latin1,另一个是utf8,这样在你的结果集中有两种字符集,mysql会报上面的错误。
一个表中不同的字段使用不同的字符集,也是一个道理。
用SHOW CREATE TABLE table_name;可以看出具体的字符集设置。解决方法:
将不同的字符集,转化成统一的字符集。
解决方案 »
- 百度或Google中文关键字转码的问题
- mysql的备份与恢复,定期备份,增量备份,一般用什么工具啊?谢谢
- 关于表的修复 问题repair table
- SQL宝典(中文版) 高清PDF版下载
- 不能建表 怎么回事
- 请问MySql怎么查询前几行啊??
- 链接时间超过connect_timeout是不是就会mysql链接报错?
- win7配置mysql odbc时出现access denied for user 'root'@'angusPC'
- sqlserver中的varchar字段插入到mysql的text中不成功
- 数据库中插入总是会提示 incorrect string value,我该怎么做才能插入中文?
- mysql中能否用 describe tables 等查询结果复制成表或应用在子查询中?
- 用mysql的c接口
ERROR 1267 (HY000): Illegal mix of collations
(utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE)
for operation 'substr_index'The reason this occurs is that usernames are stored using UTF8 (see section 11.6 UTF8 for Metadata). As a result, the USER() function and the literal string '@' have different character sets (and thus different collations): mysql> SELECT COLLATION(USER()), COLLATION('@');
+-------------------+-------------------+
| COLLATION(USER()) | COLLATION('@') |
+-------------------+-------------------+
| utf8_general_ci | latin1_swedish_ci |
+-------------------+-------------------+One way to deal with this is to tell MySQL to interpret the literal string as utf8: mysql> SELECT SUBSTRING_INDEX(USER(),_utf8'@',1);
+------------------------------------+
| SUBSTRING_INDEX(USER(),_utf8'@',1) |
+------------------------------------+
| root |
+------------------------------------+Another way is to change the connection character set and collation to utf8. You can do that with SET NAMES 'utf8' or by setting the character_set_connection and collation_connection system variables directly.
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;之前的版本可以用:
ALTER TABLE tbl_name CHARACTER SET charset_name;