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

am2000 2005-07-20 04:49:44
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.login_jsp._jspService(login_jsp.java:417)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2901)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1584)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1675)
com.mysql.jdbc.Connection.execSQL(Connection.java:2295)
com.mysql.jdbc.Connection.execSQL(Connection.java:2228)
com.mysql.jdbc.Statement.executeQuery(Statement.java:1159)
bookshop.run.login.excute(login.java:66)
org.apache.jsp.login_jsp._jspService(login_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28
...全文
1984 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
am2000 2005-07-21
  • 打赏
  • 举报
回复
After an upgrade to MySQL 4.1, the statement fails:

mysql> SELECT SUBSTRING_INDEX(USER(),'@',1);
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.

am2000 2005-07-21
  • 打赏
  • 举报
回复
是的。我查了帮助手册,说是user的字符集没有设,默认为utf8,我如何将其转为latin1.
am2000 2005-07-21
  • 打赏
  • 举报
回复
我不是要转换表的字符集,我是想把用户的字符集设置为latin1;
mathematician 2005-07-21
  • 打赏
  • 举报
回复
表的编码转换可以用(MySQL Version > 4.12)
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;

之前的版本可以用:
ALTER TABLE tbl_name CHARACTER SET charset_name;
mathematician 2005-07-20
  • 打赏
  • 举报
回复
错误是在你的结果集中有两种字符集。
比如说你在两个表联合查询,一个表的字符集是latin1,另一个是utf8,这样在你的结果集中有两种字符集,mysql会报上面的错误。
一个表中不同的字段使用不同的字符集,也是一个道理。
用SHOW CREATE TABLE table_name;可以看出具体的字符集设置。

解决方法:
将不同的字符集,转化成统一的字符集。

56,937

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧