场景:因线上有部分业务需要将数据删除后归档,为避免后续进行排查问题或者其他用途,因此将线上数据进行归档,为节约磁盘空间,将存储引擎innodb修改为tokudb。
mysql默认存储引擎为innodb,因此需要安装tokudb存储引擎,在现有mysql实例上进行安装:
1、数据库版本
percona-mysql 5.7.28
2、安装依赖包
yum -y install jemalloc-devel.x86_64 make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz vim libnuma* bzip2 xz
3、修改系统参数限制,这个操作几乎不用做,因为基础同事都会配置好最优的参数
4、修改配置文件,添加参数
[mysqld] # TokuDB settings # skip-host-cache tokudb_data_dir=/data/mysql/3306/data tokudb_log_dir=/data/mysql/3306/log tokudb_row_format=tokudb_fast tokudb_cache_size = 2G tokudb_commit_sync = 0 tokudb_directio = 1 tokudb_read_block_size = 128K tokudb_read_buf_size = 1M tokudb_commit_sync=OFF tokudb_fsync_log_period=1000 [mysqld_safe] thp-setting=never malloc-lib= /usr/lib64/libjemalloc.so
5、安装TokuDB,过程会检查THP,Selinux,jemalloc
# ps-admin --enable-tokudb -uroot -p -S /tmp/mysql3306.sock
安装成功会提示如下:
Installing TokuDB engine...
>> Successfuly installed TokuDB plugin.
6、登陆查看
(root@localhost) [(none)]> SELECT @@tokudb_version; +------------------+ | @@tokudb_version | +------------------+ | 5.7.28-31 | +------------------+ 1 row in set (0.00 sec) (root@localhost) [(none)]> show engines; +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | TokuDB | YES | Percona TokuDB Storage Engine with Fractal Tree(tm) Technology | YES | YES | YES | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
7、修改表存储引擎为tokudb
alter table table_name engine=tokudb;