搜索

Mysql设置字符编码的方法

发表于 2025-11-03 23:59:12 来源:全栈开发
Mysql设置字符编码的方法
复制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.        1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.
随机为您推荐
版权声明:本站资源均来自互联网,如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

Copyright © 2016 Powered by Mysql设置字符编码的方法,全栈开发  滇ICP备2023006006号-32sitemap

回顶部