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

下面为您介绍的MySQL字符集处理方法是将不同的MySQL字符集,转化成统一的字符集。 该方法供您参考,希望对您学习MySQL字符集方面能有所启迪。

创新互联公司主营河南网站建设的网络公司,主营网站建设方案,成都App定制开发,河南h5小程序制作搭建,河南网站营销推广欢迎河南等地区企业咨询

 
 
 
  1. After   an   upgrade   to   MySQL   4.1,   the   statement   fails:      
  2. mysql>   SELECT   SUBSTRING_INDEX(USER(),'@',1);    
  3. ERROR   1267   (HY000):   Illegal   mix   of   collations    
  4. (utf8_general_ci,IMPLICIT)   and   (latin1_swedish_ci,COERCIBLE)    
  5. for   operation   'substr_index'    
  6. 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):      
  7. mysql>   SELECT   COLLATION(USER()),   COLLATION('@');    
  8. +-------------------+-------------------+    
  9. |   COLLATION(USER())   |   COLLATION('@')         |    
  10. +-------------------+-------------------+    
  11. |   utf8_general_ci       |   latin1_swedish_ci   |    
  12. +-------------------+-------------------+    
  13. One   way   to   deal   with   this   is   to   tell   MySQL to   interpret   the   literal   string   as   utf8:      
  14. mysql>   SELECT   SUBSTRING_INDEX(USER(),_utf8'@',1);    
  15. +------------------------------------+    
  16. |   SUBSTRING_INDEX(USER(),_utf8'@',1)   |    
  17. +------------------------------------+    
  18. |   root                                                               |    
  19. +------------------------------------+    
  20. 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)

 
 
 
  1. ALTER   TABLE   tbl_name   CONVERT   TO   CHARACTER   SET   charset_name;    

之前的版本可以用:

 
 
 
  1. ALTER   TABLE   tbl_name   CHARACTER   SET   charset_name; 

网站名称:教您如何将不同的MySQL字符集转化成统一的字符集
浏览路径:http://www.hantingmc.com/qtweb/news31/53781.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联