安装
安装主要包括两种方法:1)rpm安装 2)源码编译
1. rpm安装
此方式是比较简单的方式,按照Percona安装说明文档指示的方法操作即可。
sudo rpm -i percona-release-0.0-1.x86_64.rpm
接下来安装Percona-Server-tokudb-56.x86_64
sudo yum install Percona-Server-tokudb-56.x86_64
在这一步安装过程中,安装程序会向屏幕输出很多信息,可根据具体信息查找问题或直接success。tokudb和mysqld存在冲突,强烈建议使用rpm包安装时机器上不存在mysqld,否则会报错。
安装好后,就可以启动mysqld_safe,然后可以正常访问mysqld。
2. 源码编译
Percona的tokudb是以一个单独的包进行发布的,因此源码编译需要分别安装Percona 5.6.19和tokudb
tokudb下载当前最新版:
http://www.percona.com/downloads/Percona-Server-5.6/Percona-Server-5.6.17-66.0/source/tarball/
选择其中的percona-server-5.6.17-66.0.tokudb.tar.gz,下载后解压缩,将其中的storage/tokudb放到Mysql相关目录。
编译时cmake需要指定DWITH_TOKUDB_STORAGE_ENGINE=1,然后执行make /make install。
编译tokudb需要gcc版本大于4.8,cmake版本大于2.8.9。
使用TokuDB存储引擎
tokuDB默认是使用Module方式编译的,因此在使用前需要首先Install,具体方式如下
1INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so'; 2INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so'; 3INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so'; 4INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so'; 5INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so'; 6INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so'; 7INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';
后续通过
show engines/show plugins/ select @@tokudb_version 就可以看到tokudb相关的内容。
建表
在install相关so之后,可以直接创建tokudb类型的表,Percona给出了一个例子,看起来和创建innodb的表没有什么区别。
1mysql> CREATE TABLE `City` ( 2 `ID` int(11) NOT NULL AUTO_INCREMENT, 3 `Name` char(35) NOT NULL DEFAULT '', 4 `CountryCode` char(3) NOT NULL DEFAULT '', 5 `District` char(20) NOT NULL DEFAULT '', 6 `Population` int(11) NOT NULL DEFAULT '0', 7 PRIMARY KEY (`ID`), 8 KEY `CountryCode` (`CountryCode`) 9) ENGINE=TokuDB
也可以将其他存储引擎的表修改成tokudb:
mysql> ALTER TABLE City ENGINE=TokuDB;
经确认可以在innodb和tokudb两个存储引擎之间相互转换。
同一事务内对不同存储引擎表进行操作
经测试,同一个事务内可以对innodb/tokudb分别进行操作,如下:
1mysql> insert into City_tokudb(ID) values(1); 2Query OK, 1 row affected (0.00 sec) 3 4mysql> insert into City_innodb(ID) values(1); 5Query OK, 1 row affected (0.00 sec) 6 7mysql> begin; 8Query OK, 0 rows affected (0.00 sec) 9 10mysql> insert into City_innodb(ID) values(2); 11Query OK, 1 row affected (0.00 sec) 12 13mysql> insert into City_tokudb(ID) values(2); 14Query OK, 1 row affected (0.00 sec) 15 16mysql> commit; 17Query OK, 0 rows affected (0.00 sec) 18 19mysql> select * from City_innodb; 20+----+------+-------------+----------+------------+ 21| ID | Name | CountryCode | District | Population | 22+----+------+-------------+----------+------------+ 23| 1 | | | | 0 | 24| 2 | | | | 0 | 25+----+------+-------------+----------+------------+ 262 rows in set (0.00 sec) 27 28mysql> select * from City_tokudb; 29+----+------+-------------+----------+------------+ 30| ID | Name | CountryCode | District | Population | 31+----+------+-------------+----------+------------+ 32| 1 | | | | 0 | 33| 2 | | | | 0 | 34+----+------+-------------+----------+------------+ 352 rows in set (0.00 sec)
复制相关
由于binlog和存储引擎是相互独立的,因此理论上复制不应受到TokuDB的影响。此处,以常规的主备搭建为基础,在主库上对TokuDB的表分别执行建表,增删改查操作,并在备库上确认复制数据无误。
常规的主备搭建流程参见:
http://dev.mysql.com/doc/refman/5.6/en/replication-howto-newservers.html
主库执行的操作:
1mysql> CREATE TABLE `City_repl` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`) ) ENGINE=TokuDB; 2Query OK, 0 rows affected (0.01 sec) 3 4mysql> insert into City_repl(ID) values(1); 5Query OK, 1 row affected (0.00 sec) 6 7mysql> insert into City_repl(ID) values(2); 8Query OK, 1 row affected (0.00 sec) 9 10mysql> delete from City_repl where ID=1; 11Query OK, 1 row affected (0.00 sec) 12 13mysql> update City_repl set ID=3 where ID=2; 14Query OK, 1 row affected (0.00 sec) 15Rows matched: 1 Changed: 1 Warnings: 0
相应的备库同步执行查询结果如下:
1mysql> show tables; 2+----------------+ 3| Tables_in_test | 4+----------------+ 5| City_repl | 6+----------------+ 71 row in set (0.00 sec) 8 9mysql> select * from City_repl; 10+----+------+-------------+----------+------------+ 11| ID | Name | CountryCode | District | Population | 12+----+------+-------------+----------+------------+ 13| 1 | | | | 0 | 14| 2 | | | | 0 | 15+----+------+-------------+----------+------------+ 162 rows in set (0.00 sec) 17 18mysql> select * from City_repl; 19+----+------+-------------+----------+------------+ 20| ID | Name | CountryCode | District | Population | 21+----+------+-------------+----------+------------+ 22| 2 | | | | 0 | 23+----+------+-------------+----------+------------+ 241 row in set (0.00 sec) 25 26mysql> select * from City_repl; 27+----+------+-------------+----------+------------+ 28| ID | Name | CountryCode | District | Population | 29+----+------+-------------+----------+------------+ 30| 3 | | | | 0 | 31+----+------+-------------+----------+------------+
可见简单的针对TokuDB的增删改查操作,备份是可以正常工作的
备份相关
Percona Xtrabackup当前并不支持TokuDB tables的备份,从Percona官方观点来看,其在近期内也并没有支持TokuDB的计划。
TokuDB企业版提供Hot Backup的方案,其实现原理参见:TokuDB Hot Backup – Part 1 TokuDB Hot Backup – Part 2, 当然这不会是我们考虑的方案。
Percona推荐使用LVM或是mysqldumper来备份TokuDB表,而网易在《程序员》上发表的一篇文章中提到其使用mysqldump对TokuDB进行备份。