虚拟主机域名注册-常见问题数据库问题 → 数据库问题

教您如何将不同的MySQL字符集转化成统一的字符集

  下面为您介绍的MySQL字符集处理方法是将不同的MySQL字符集,转化成统一的字符集。 该方法供您参考,希望对您学习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.

  表的编码转换可以用:(MySQL Version > 4.12)

  ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;

  之前的版本可以用:

  ALTER TABLE tbl_name CHARACTER SET charset_name;




免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:bkook@qq.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
【 双击滚屏 】 【 推荐朋友 】 【 收藏 】 【 打印 】 【 关闭 】 【 字体: 】 
上一篇:SQL server组合查询+sql常用函数有哪些?
下一篇:MySQL数据库优化SQL语句的步骤4
  >> 相关文章
没有相关文章。