Linux 配置源碼安裝的MySQL同時支援多個字元集

來源:互聯網
上載者:User

一、mysql的多字元集支援
    1、設定mysqld服務同時支援多個字元集
        將mysqld服務的預設字元集改為utf8,並同時支援latin1、gbk、gb2312、big5、ascii字元集。可以為不同的資料庫、表使用不同的字元集編碼。

        Step1:./configure步驟時需增加字元集支援選項,例如:
shell> ./configure --with-charset=utf8 --with-collation=utf8_bin --with-extra-charsets=big5,ascii,gb2312,gbk,utf8,latin1

          //預設的字元集預設為latin1。
          //其中,utf8對應可用的collation值為:utf8_bin、utf8_general_ci、utf8_unicode_ci
          //extra支援也可以使用 "--with-extra-charsets=all"。

        Step2:在make步驟之前,修改config.h標頭檔,尋找utf8、gbk、gb2312等定義字元集變數的行,確認有如下內容(如果沒有則需要手動添加),例如:
#define HAVE_CHARSET_ascii 1
#define HAVE_CHARSET_big5 1
#define HAVE_CHARSET_gb2312 1
#define HAVE_CHARSET_gbk 1
#define HAVE_CHARSET_latin1 1
#define HAVE_CHARSET_utf8 1

          //一開始沒有修改config.h,費了好多功夫,"mysql>"環境中使用非預設字元集時總報"Error 1115"錯誤:
mysqld> set names gbk;
ERROR 1115 (42000): Unknown character set: 'gbk'
          //後來發現在./configure完成後,config.h檔案中並沒有自動開啟gbk、gb2312等變數定義,不得不手動修改添加。

    2、驗證mysqld服務的多字元集支援
        1) 查看當前mysql資料庫支援的字元集
mysql> show character set;

        2) 查看對應字元集可用的校對規則
mysql> show collation like 'gb%';
mysql> show collation like 'utf8%';

        3) 查看當前mysql伺服器使用的預設字元集狀態
mysql> status
……
Server characterset:  utf8
Db     characterset:  utf8
Client characterset:  utf8
Conn.  characterset:  utf8

        4) 在建立資料庫時指定使用的預設字元集:
mysql> create database testdb default character set utf8;
mysql> show create database testdb;     //驗證資料庫建立資訊

        5) 在建立資料表時指定使用的預設字元集:
mysql> create table testdb.tb1 ( id int(10) unsigned NOT NULL AUTO_INCREMENT,name varchar(15) NOT NULL default '',PRIMARY KEY  (id) ) ENGINE=MyISAM DEFAULT CHARACTER SET gb2312;
mysql> show create table testdb.tb1;     //驗證資料表建立資訊

        6) 在mysql>用戶端環境中設定使用的預設字元集
mysql> set NAMES utf8;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.