MySQL中怎么查看字符集,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)武義,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
(1) 最簡(jiǎn)單的修改方法,就是修改mysql的my.ini文件中的字符集鍵值,
如 default-character-set = utf8
character_set_server = utf8
修改完后,重啟mysql的服務(wù),service mysql restart
使用 mysql> SHOW VARIABLES LIKE 'character%';查看,發(fā)現(xiàn)數(shù)據(jù)庫(kù)編碼均已改成utf8
+--------------------------+---------------------------------+ | Variable_name | Value | +--------------------------+---------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | D:"mysql-5.0.37"share"charsets" | +--------------------------+---------------------------------+
(2) 還有一種修改mysql默認(rèn)字符集的方法,就是使用mysql的命令
mysql> SET character_set_client = utf8 ; mysql> SET character_set_connection = utf8 ; mysql> SET character_set_database = utf8 ; mysql> SET character_set_results = utf8 ; mysql> SET character_set_server = utf8 ; mysql> SET collation_connection = utf8 ; mysql> SET collation_database = utf8 ; mysql> SET collation_server = utf8 ;
一般就算設(shè)置了表的mysql默認(rèn)字符集為utf8并且通過(guò)UTF-8編碼發(fā)送查詢,你會(huì)發(fā)現(xiàn)存入數(shù)據(jù)庫(kù)的仍然是亂碼。問(wèn)題就出在這個(gè)connection連接層上。解決方法是在發(fā)送查詢前執(zhí)行一下下面這句:
SET NAMES 'utf8';
它相當(dāng)于下面的三句指令:
SET character_set_client = utf8; SET character_set_results = utf8; SET character_set_connection = utf8;
關(guān)于mysql中怎么查看字符集問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。