自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Mysql設置字符編碼的方法

數(shù)據(jù)庫 MySQL
在Mysql數(shù)據(jù)庫中,如果使用兩種字符集,mysql會報錯誤,如果將不同的字符集,轉(zhuǎn)化成統(tǒng)一的字符集,就可以解決這一問題。

Mysql設置字符編碼可以解決一些常見的問題,比如使用不同的字符集出錯的問題,下面就是Mysql設置字符編碼解決該問題的具體介紹。

錯誤是在你的結果集中有兩種字符集。   

比如說你在兩個表聯(lián)合查詢,一個表的字符集是latin1,另一個是utf8,
這樣在你的結果集中有兩種字符集,mysql會報錯誤。   

一個表中不同的字段使用不同的字符集,也是一個道理。   

用SHOW   CREATE   TABLE   table_name;可以看出具體的字符集設置。

查了幫助手冊,說是user的字符集沒有設,默認為utf8,將其轉(zhuǎn)為latin1或gb2312等字符集

解決方法:  

將不同的字符集,轉(zhuǎn)化成統(tǒng)一的字符集。  下面就是Mysql設置字符編碼的方法。

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

表的編碼轉(zhuǎn)換可以用:(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修改字段的語句寫法

MySQL中多表刪除方法

詳解MySQL如何鏈接遠程SQL

MySQL集群簡介與配置詳解

MySQL數(shù)據(jù)庫的23個特別注意事項

 

責任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關推薦

2011-07-27 15:28:10

MySQL數(shù)據(jù)庫字符編碼集

2010-05-11 17:45:17

MySQL字符

2012-03-02 10:38:33

MySQL

2010-05-17 09:25:34

MySql 編碼設置

2019-05-29 09:38:44

MySQL字符編碼數(shù)據(jù)庫

2009-06-08 19:52:47

Eclipse字符編碼

2023-04-13 00:24:00

前端編碼JavaScrip

2012-03-09 10:27:37

Java

2010-10-14 10:43:03

MySQL用戶權限

2010-10-08 15:42:39

MySQL設置自增字段

2010-10-14 11:52:38

MySQL字符集

2016-05-12 15:51:08

前端開發(fā)字符編碼

2010-10-09 11:12:32

mysql默認字符集

2022-02-17 09:12:55

MySQL數(shù)據(jù)庫設置變量

2009-04-23 09:16:46

Java字符串編碼

2010-10-09 10:35:46

MySQL字符集

2010-10-09 11:36:30

MySQL字符集

2010-05-12 15:34:26

MySQL編碼設置

2010-11-26 11:34:32

MySQL截取字符串函

2009-02-12 10:14:16

點贊
收藏

51CTO技術棧公眾號