Mariadb對中文字元集的支援

來源:互聯網
上載者:User

今天在寫Django程式的時候,將Mariadb作為資料庫,但是Mariadb(mysql的一個分支,完全相容mysql,現由mysql創始人主導開發)預設不支援中文字元集,於是在網上搜集答案沒有找到合適的解決辦法,倒是Mariadb不能用了,只好卸載重裝Mariadb,遇到一些麻煩,用的是ubuntu-14.04.

卸載有三步:1. 刪除mysql-server: sudo apt-get autoremove --purge mysql-server-5.5;2. sudo apt-get remove mysql-common;3.清理殘餘資料,這一步很重要: sudo dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
然後重新安裝mariadb即可sudo apt-get install mariadb-server.

再來解決中文字元集的問題

開啟檔案:vim /etc/mysql/my.cnf

在[client](也就是用戶端)配置下添加一行:

default-character-set=utf8

在[mysqld](也就是mysql伺服器配置)下添加兩行:

init_connect='SET NAMES utf8'

character-set-server=utf8

然後重啟mysql服務

sudo service mysql restart

這樣在django應用裡就可以順利地使用中語言了,搞定,這是個老問題,以作記錄。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.