tokuDB存儲引擎的安裝、配置、使用及注意事項

tokuDB部署

一、安裝包下載

       Percona-Server-5.6.22-rel71.0-726.Linux.x86_64.tar.gz:

http://www.percona.com/downloads/Percona-Server-5.6/Percona-Server-5.6.22-72.0/binary/tarball/Percona-Server-5.6.22-rel71.0-726.Linux.x86_64.tar.gz

       Percona-Server-5.6.22-rel72.0-738.TokuDB.Linux.x86_64.tar.gz:

http://www.percona.com/downloads/Percona-Server-5.6/Percona-Server-5.6.22-72.0/binary/tarball/Percona-Server-5.6.22-rel72.0-738.TokuDB.Linux.x86_64.tar.gz

       使用的是:

       https://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/tarball/

       Percona-Server-5.6.24-rel72.2-Linux.x86_64

       Percona-Server-5.6.24-rel72.2-TokuDB.Linux.x86_64.ssl100.tar.gz

     

       停止mysql server;

 

二、相關目錄  mysql存放目錄

       BASEDIR=/opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64

三、配置文件 添加

     [mysqld_safe]

      malloc-lib= /opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64/lib/mysql/libjemalloc.so

      plugin-dir = /opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64/lib/mysql/plugin/

      plugin-load=ha_tokudb.so

四、安裝步驟

      1. 解壓tokudb的包

          tar -zxf   Percona-Server-5.6.24-rel72.2-TokuDB.Linux.x86_64.ssl100.tar.gz

      2. 解壓後,目錄如下:

          # ls Percona-Server-5.6.24-rel72.2-Linux.x86_64.ssl100

          bin  lib  mysql-test  README-TOKUDB

      3. 把相關目錄放到BASEDIR下

          cp -r Percona-Server-5.6.24-rel72.2-Linux.x86_64.ssl100/* /opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64/

      4. 啓動之前,停用transparent huge pages 

          修改系統參數

          echo never > /sys/kernel/mm/transparent_hugepage/enabled

          echo never > /sys/kernel/mm/transparent_hugepage/defrag

          echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled

          echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag

  建議寫到 /etc/rc.local 中,重啓後也可生效

      5. 啓動數據庫

      6. 手動添加plugin

           INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';

INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';

###安裝這個後會生成toku相應的日誌文件和回滾文件等,需要刪除

(如果指定的數據文件和日誌文件不在默認的mysql數據目錄下的話)然後在my.cnf配置好toku的參數後重啓即可

 

    推薦參數:

    tokudb_commit_sync=ON

    tokudb_cache_size=10G ##指定tokuDB可使用的緩存類似innodb 的innodb_buffer_pool_size 默認是物理內存的50%

    tokudb_directio=ON          ##寫操作不經過緩存,直接寫入磁盤

    row_format=tokudb_fast   ##指定行格式默認是tokudb_zlib

    tokudb_tmp_dir=/database1/mysql_tmpdir

    tokudb_write_status_frequency =1

    tokudb_read_status_frequency=1   

    tokudb_data_dir=/xxx/yyy

    tokudb_log_dir=/xxx /yyy

    注意指定的目錄必須存在並且具有可訪問的權限

 

 

    如果要卸載

UNINSTALL PLUGIN  tokudb ;

UNINSTALL PLUGIN  tokudb_file_map ;

UNINSTALL PLUGIN  tokudb_fractal_tree_info;

UNINSTALL PLUGIN  tokudb_fractal_tree_block_map;

UNINSTALL PLUGIN  tokudb_trx ;

UNINSTALL PLUGIN  tokudb_locks;

UNINSTALL PLUGIN  tokudb_lock_waits;

      另外進入數據目錄刪除tokudb相關的文件

      並且註釋掉my.cnf toku相關的配置參數即可

 

   安裝當中可能的報錯

'/database1/mysql/percona-sever-4005/lib/mysql/plugin/ha_tokudb.so' (errno: 13 /database1/mysql/percona-sever-4005/lib/mysql/plugin/ha_tokudb.so:

cannot open shared object file: No such file or directory)

    很明顯是數據庫插件目錄沒有ha_tokudb.so 共享庫,做一個軟連接或拷貝ha_tokudb.so到percoan mysql的plugin目錄下即可

    如:

    ln -s /usr/local/src/percona-Server-5.6.17-rel66.0-608.Linux.x86_64/lib/mysql/plugin/ha_tokudb.so /database1/mysql/percona-sever-4005/lib/mysql/plugin/ha_tokudb.so

 

 

     最後show engines;即可查看到tokudb引擎

 

      7. 檢查添加結果

          show engines;

          show plugins;

 

使用tokudb創建表 

   CREATE TABLE `toku` (

  `pid` varchar(32) NOT NULL DEFAULT '',

  `CREATETIME` datetime NOT NULL,

  `UPDATETIMES` datetime NOT NULL,

  `USER_ID` bigint(20) NOT NULL,

  `HOMEWORK_ID` varchar(255) DEFAULT NULL,

  `COMPLETE_PRACTICE` int(11) NOT NULL DEFAULT '0',

  `note` varchar(256) NOT NULL DEFAULT '',

  `CLAZZ_ID` bigint(20) NOT NULL DEFAULT '0',

  `score` bigint(20) NOT NULL DEFAULT '0',

  `NOTE_CHECKEDS` bit(1) NOT NULL DEFAULT b'0',

  PRIMARY KEY (`pid`)

) ENGINE=TokuDB

(4)、 一些注意事項

     1、alter table xxx engine=tokudb 的情況會加metadata鎖阻塞插入更新, 而myql-5.6.17 innodb引擎則不會導致阻塞。    

     2、只有char, varchar, varbinary, and integer  字段類型的擴展才支持online  ddl【縮減不支持online 操作】,注意修改的時候字段屬性不能發生變化,同時也不能是任何主鍵或二級索引的字段【二級索引的話,可以先刪除二級索引,不過tokuDB創建索引二級索引並不快】,否則會導致copy表。

     3、 修改列名的時候必須是單個列修改,如果是一條語句同時修改多條語句則會copy表。

     4、這些字段TIME, ENUM, BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB類型不支持online ddl。   

     其他的一些限制詳情可參考官網

 

(5)、tokuDB事物、鎖信息查看

      查看事物情況:

       SELECT * FROM information_schema.tokudb_trx,

        information_schema.processlist

        WHERE trx_mysql_thread_id = id;

     

       查看鎖的情況

        SELECT id FROM information_schema.tokudb_locks,

        information_schema.processlist

        WHERE locks_mysql_thread_id = id;

     

     警告:

       不要移動任何TokuDB相關的文件、否則會導致數據庫崩潰並且需要使用備份才能進行恢復。

 

(6)、 關於TokuDB行格式

    tokudb_row_format 可以設置如下的幾個值:

    tokudb_default: 設置默認的壓縮行爲。在 TokuDB 7.1.0版本,默認使用zlib 庫進行壓縮,未來版本可能會改變。

    tokudb_fast: 使用quicklz 庫的壓縮模式。

    tokudb_small: 使用 lzma 庫的壓縮模式。

    tokudb_zlib: 使用 zlib 庫的壓縮模式,提供了中等級別的壓縮比和中等級別的CPU消耗。

             

             tokudb_quicklz: 使用 quicklz 庫的壓縮模式, 提供了輕量級的壓縮比和較低基本的CPU消耗。

             tokudb_lzma: 使用lzma庫壓縮模式,提供了高壓縮比和高CPU消耗。

             tokudb_uncompressed: 不使用壓縮模式。

    可以使用如下命令修改行格式:

     ALTER TABLE table_name ROW_FORMAT=row_format; 

     注意修改行格式的操作也是online 操作。

 [

#tokudb

malloc-lib= /opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64/lib/mysql/libjemalloc.so

plugin-dir = /opt/freeware/Percona-Server-5.6.24-rel72.2-Linux.x86_64/lib/mysql/plugin/

plugin-load=ha_tokudb.so

 

 

tokudb-data-dir = /data/users/mysusr01/mysql/tokudbData

tokudb-log-dir = /data/users/mysusr01/mysql/tokudbLog

tokudb_tmp_dir=/data/users/mysusr01/mysql/tokudbTMP

 

#TokuDB的行模式,建議用 FAST 就足夠了,如果磁盤空間很緊張,建議用 SMALL

#tokudb_row_format = tokudb_small

tokudb_row_format = tokudb_fast

tokudb_cache_size = 2G

 

#其他大部分配置其實可以不用修改的,只需要幾個關鍵配置即可

tokudb_commit_sync = 0     #放入mysqld參數下面

tokudb_directio = 1       #放入mysqld參數下面

tokudb_read_block_size = 128K

tokudb_read_buf_size = 128K

 

tokudb_write_status_frequency =1

tokudb_read_status_frequency=1   

]


 


tokudb存在的問題:

  • 官方分支還沒很好的支持

  • 熱備方案問題,目前只有企業版纔有

  • 還是有bug的,版本更新比較快,不建議在覈心業務上用


備份相關

Percona Xtrabackup當前並不支持TokuDB tables的備份,從Percona官方觀點來看,其在近期內也並沒有支持TokuDB的計劃。

TokuDB企業版提供Hot Backup的方案,其實現原理參見:TokuDB Hot Backup – Part 1  TokuDB Hot Backup – Part 2, 當然這不會是我們考慮的方案。

Percona推薦使用LVM或是mysqldumper來備份TokuDB表,而網易在《程序員》上發表的一篇文章中提到其使用mysqldumpTokuDB進行備份。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章