主頁(yè) > 知識(shí)庫(kù) > Ubuntu修改mysql默認(rèn)編碼的方法

Ubuntu修改mysql默認(rèn)編碼的方法

熱門(mén)標(biāo)簽:各種地圖標(biāo)注 企業(yè)電話(huà)機(jī)器人靠譜嗎 智能外呼系統(tǒng)的選購(gòu) 河北點(diǎn)撥外呼系統(tǒng)哪家公司做的好 地圖標(biāo)注不在現(xiàn)場(chǎng)怎么上傳門(mén)頭標(biāo) 文德數(shù)慧科技有限公司 地圖標(biāo)注員騙局 400電話(huà)申請(qǐng)商客通 福州營(yíng)銷(xiāo)電銷(xiāo)機(jī)器人招商

修改mysql的配置文件,使數(shù)據(jù)庫(kù)與服務(wù)器操作系統(tǒng)的字符集設(shè)置一致。
    vi /etc/my.cnf 設(shè)置(如果沒(méi)有發(fā)現(xiàn)這個(gè)文件,就新建1個(gè))
    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    default-character-set=utf8  (增加的關(guān)鍵一句,使得數(shù)據(jù)庫(kù)缺省以u(píng)tf8存儲(chǔ))
    當(dāng)然,修改后,要重啟數(shù)據(jù)庫(kù)。
   
    再次用mysql -u root -p命令進(jìn)入數(shù)據(jù)庫(kù)系統(tǒng),用SHOW VARIABLES LIKE 'character_set_%';命令查看到如下內(nèi)容:
+--------------------------+-----------------------------------------------------------------------+
| Variable_name            | Value                                                                 |
+--------------------------+-----------------------------------------------------------------------+
| character_set_client     | latin1                                                                |
| character_set_connection | latin1                                                                |
| character_set_database   | utf8                                                                  |
| character_set_filesystem | binary                                                                |
| character_set_results    | latin1                                                                |
| character_set_server     | utf8                                                                  |
| character_set_system     | utf8                                                                  |
| character_sets_dir       | /usr/local/mysql-5.1.20-beta-linux-i686-glibc23/share/mysql/charsets/ |
+--------------------------+-----------------------------------------------------------------------+
    發(fā)現(xiàn)關(guān)鍵項(xiàng)目已經(jīng)用了utf8,但這樣還不夠,還要保證客戶(hù)端也是用utf8的字符集來(lái)操作的。
    登錄的時(shí)候,要用以下命令:mysql --default-character-set=utf8 -u root -p
  
    再次用SHOW VARIABLES LIKE 'character_set_%';命令查看,結(jié)果變成了:
+--------------------------+-----------------------------------------------------------------------+
| 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       | /usr/local/mysql-5.1.20-beta-linux-i686-glibc23/share/mysql/charsets/ |
+--------------------------+-----------------------------------------------------------------------+
    這樣才能保證客戶(hù)端所發(fā)命令都是基于utf8格式的,比如說(shuō)建立數(shù)據(jù)庫(kù)和表,默認(rèn)就會(huì)以u(píng)tf8編碼,而無(wú)須再次指定。


需要說(shuō)明一下,如果在修改編碼之前已經(jīng)建好數(shù)據(jù)庫(kù),需要?jiǎng)h掉原來(lái),重新建立數(shù)據(jù)庫(kù)。

標(biāo)簽:曲靖 南陽(yáng) 潛江 新余 雞西 鎮(zhèn)江 長(zhǎng)沙 鎮(zhèn)江

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Ubuntu修改mysql默認(rèn)編碼的方法》,本文關(guān)鍵詞  Ubuntu,修改,mysql,默認(rèn),編碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ubuntu修改mysql默認(rèn)編碼的方法》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Ubuntu修改mysql默認(rèn)編碼的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章