新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
教您如何將不同的MySQL字符集轉(zhuǎn)化成統(tǒng)一的字符集
下面為您介紹的MySQL字符集處理方法是將不同的MySQL字符集,轉(zhuǎn)化成統(tǒng)一的字符集。 該方法供您參考,希望對(duì)您學(xué)習(xí)MySQL字符集方面能有所啟迪。

創(chuàng)新互聯(lián)公司主營(yíng)河南網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都App定制開(kāi)發(fā),河南h5小程序制作搭建,河南網(wǎng)站營(yíng)銷推廣歡迎河南等地區(qū)企業(yè)咨詢
- 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.
表的編碼轉(zhuǎn)換可以用:(MySQL Version > 4.12)
- ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;
之前的版本可以用:
- ALTER TABLE tbl_name CHARACTER SET charset_name;
當(dāng)前名稱:教您如何將不同的MySQL字符集轉(zhuǎn)化成統(tǒng)一的字符集
轉(zhuǎn)載注明:http://m.5511xx.com/article/dhcdooj.html


咨詢
建站咨詢
