tokuDB 安装与备份小记

线上的数据增长越来越快,数据量的增长也愈来愈大,尤其是日志类数据,这对于数据迁移、数据备份恢复而言,都是一个非常大的挑战。

于是想到了 13 年开源 tokuDB 存储引擎,来解决我们迫在眉睫的容量问题。

TokuDB 是一个高性能、支持事务处理的 MySQL 和 MariaDB 的存储引擎。TokuDB 的主要特点是高压缩比,高 INSERT 性能,支持大多数在线修改索引、添加字段,特别适合像 Zabbix 这种高 INSERT,少 UPDATE 的应用场景。

由于在 Percona 5.6 之后,tokuDB 无法单独作为一个插件直接在 MySQL 社区版上使用(可以成功安装插件,但使用时会陷入无限重启/(ㄒoㄒ)/~~),因而,本次使用 Percona MySQL 最新版 5.7.18,操作系统是 64 bit CentOS 6.9。

安装

1 依赖安装

yum install libaio-devel numactl -y

2 初始化安装和 MySQL 社区版安装一样

3 关闭 MySQL 服务,添加 tokuDB 插件配置,并启动

[mysqld_safe]
malloc-lib=/usr/lib64/libjemalloc.so.1
plugin-dir = /usr/local/mysql/lib/mysql/plugin/
plugin-load=ha_tokudb.so

注意:5.7 以后版本,为了安全,需要将 libjemalloc 复制到 /usr/lib /usr/lib64 目录下才能正确读取

4 安装 tokuDB

ps_tokudb_admin -S /tmp/mysql.sock --enable -uroot -pxxx

注意:此时可以加上 --enable-backup 热备份插件功能

5 添加 tokuDB 配置项

##tokuDB
#tokudb-data-dir = /data/mysql/mysql3306/tokudbData
#tokudb-log-dir = /data/mysql/mysql3306/tokudbLog
#TokuDB的行模式,建议用 FAST ,如果磁盘空间很紧张,建议用 SMALL
    #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: 不使用压缩模式。
tokudb_row_format = tokudb_fast
tokudb_cache_size = 1G ###建议内存的一半
tokudb_commit_sync = 0
tokudb_directio = 1
tokudb_read_block_size = 128K
tokudb_read_buf_size = 128K

备份

1 使用 mysqldump 备份

使用 Percona 版本的 mysqldump 可以备份 tokuDB 的数据,并且额外提供了一个参数 lock-for-backup 来保证数据一致性。

eg:

mysqldump --single-transaction --lock-for-backup --master-data=2 -S /tmp/mysql.sock -uroot -p -A > xxx-2017-6-28.sql

mysqldump has also been extended with a new option, lock-for-backup (disabled by default). When used together with the --single-transaction option, the option makes mysqldump issue LOCK TABLES FOR BACKUP before starting the dump operation to prevent unsafe statements that would normally result in an inconsistent backup.
When used without the single-transaction option, lock-for-backup is automatically converted to lock-all-tables.
Option lock-for-backup is mutually exclusive with lock-all-tables, i.e. specifying both on the command line will lead to an error.
If the backup locks feature is not supported by the target server, but lock-for-backup is specified on the command line, mysqldump aborts with an error. [Link]

2 使用 tokudb-xtrabackup 备份

基于 Percona Xtrabackup 的兼容 tokuDB 的备份工具

yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bison libtool ncurses-devel libgcrypt-devel libev-devel libcurl-devel vim-common  -y
  
git clone https://github.com/BohuTANG/tokudb-xtrabackup

cd tokudb-xtrabackup

cmake .\
  -DBUILD_CONFIG=xtrabackup_release\
  -DWITH_BOOST=extra/boost/boost_1_59_0.tar.gz\
  -DWITH_MAN_PAGES=OFF\
  -DCMAKE_INSTALL_PREFIX=/usr/local/tokudb-xtrabackup

  make

make install

注意: gcc 的版本最好要 >= 4.8

eg:

/usr/local/tokudb-xtrabackup/bin/innobackupex --defaults-file=/path/to/my.cnf --user=root --password=xxx --no-timestamp /path/to/backup

/usr/local/tokudb-xtrabackup/bin/innobackupex --apply-log /path/to/backup

/usr/local/tokudb-xtrabackup/bin/innobackupex --defaults-file=/path/to/my.cnf --copy-back /path/to/backup

Link to

3 使用 tokudb-backup-plugin 备份

官方提供的一个热备份插件

ps_tokudb_admin --enable-backup -S /tmp/mysql.sock -uroot -pxxx

用此命令安装之后,确认配置文件已添加相应的配置项:

# tokudb
innodb_use_native_aio=off
[mysqld_safe]
preload-hotbackup
thp-setting=never

eg:

mysql> set tokudb_backup_dir='/path/to/backup';

Link to

Link to

实验代码

安装

[root@glon_ho ~]# cat /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m
[root@glon_ho ~]# chkconfig iptables off
[root@glon_ho ~]# service iptables stop
[root@glon_ho ~]# getenforce
Disabled
[root@glon_ho ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
[root@glon_ho ~]# yum install libaio-devel mlocate -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package libaio-devel.x86_64 0:0.3.107-10.el6 will be installed
---> Package mlocate.x86_64 0:0.22.2-6.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
 Package                                         Arch                                      Version                                             Repository                               Size
=============================================================================================================================================================================================
Installing:
 libaio-devel                                    x86_64                                    0.3.107-10.el6                                      base                                     13 k
 mlocate                                         x86_64                                    0.22.2-6.el6                                        base                                     86 k
Transaction Summary
=============================================================================================================================================================================================
Install       2 Package(s)
Total download size: 99 k
Installed size: 302 k
Downloading Packages:
(1/2): libaio-devel-0.3.107-10.el6.x86_64.rpm                                                                                                                         |  13 kB     00:00    
(2/2): mlocate-0.22.2-6.el6.x86_64.rpm                                                                                                                                |  86 kB     00:00    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        306 kB/s |  99 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mlocate-0.22.2-6.el6.x86_64                                                                                                                                               1/2
  Installing : libaio-devel-0.3.107-10.el6.x86_64                                                                                                                                        2/2
  Verifying  : libaio-devel-0.3.107-10.el6.x86_64                                                                                                                                        1/2
  Verifying  : mlocate-0.22.2-6.el6.x86_64                                                                                                                                               2/2
Installed:
  libaio-devel.x86_64 0:0.3.107-10.el6                                                             mlocate.x86_64 0:0.22.2-6.el6                                                           
Complete!
[root@glon_ho ~]# yum install numactl -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package numactl.x86_64 0:2.0.9-2.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
 Package                                      Arch                                        Version                                            Repository                                 Size
=============================================================================================================================================================================================
Installing:
 numactl                                      x86_64                                      2.0.9-2.el6                                        base                                       74 k
Transaction Summary
=============================================================================================================================================================================================
Install       1 Package(s)
Total download size: 74 k
Installed size: 171 k
Downloading Packages:
numactl-2.0.9-2.el6.x86_64.rpm                                                                                                                                        |  74 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : numactl-2.0.9-2.el6.x86_64                                                                                                                                                1/1
  Verifying  : numactl-2.0.9-2.el6.x86_64                                                                                                                                                1/1
Installed:
  numactl.x86_64 0:2.0.9-2.el6                                                                                                                                                              
Complete!
[root@glon_ho ~]#
[root@glon_ho ~]# cd /opt/
[root@glon_ho opt]# tar -zxf /vagrant_data/Percona-Server-5.7.18-15-Linux.x86_64.ssl101.tar.gz
[root@glon_ho opt]#
[root@glon_ho local]# sudo groupadd mysql
[root@glon_ho local]# sudo useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql
[root@glon_ho local]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
[root@glon_ho local]# chown -R mysql:mysql /usr/local/mysql
[root@glon_ho local]# chown -R mysql:mysql /usr/local/mysql/
[root@glon_ho local]# ll mysql/
total 128
drwxr-xr-x  2 mysql mysql  4096 May 25 10:01 bin
-rw-r--r--  1 mysql mysql 17987 May 25 08:03 COPYING
-rw-r--r--  1 mysql mysql 34520 May 25 09:44 COPYING.AGPLv3
-rw-r--r--  1 mysql mysql 17987 May 25 09:44 COPYING.GPLv2
-rw-r--r--  1 mysql mysql  1703 May 25 10:03 COPYING-jemalloc
drwxr-xr-x  2 mysql mysql  4096 May 25 10:01 docs
drwxr-xr-x  3 mysql mysql  4096 May 25 10:01 include
drwxr-xr-x  5 mysql mysql  4096 May 25 10:01 lib
drwxr-xr-x  4 mysql mysql  4096 May 25 10:01 man
drwxr-xr-x 10 mysql mysql  4096 May 25 10:01 mysql-test
-rw-r--r--  1 mysql mysql  2211 May 25 09:44 PATENTS
-rw-r--r--  1 mysql mysql  4442 May 25 09:44 README.md
-rw-r--r--  1 mysql mysql  2478 May 25 08:03 README.MySQL
drwxr-xr-x 28 mysql mysql  4096 May 25 10:01 share
drwxr-xr-x  2 mysql mysql  4096 May 25 10:01 support-files
[root@glon_ho local]# mkdir /data/mysql/mysql3306/{data,logs,tmp} -p
[root@glon_ho local]# chown -R mysql:mysql /data/
[root@glon_ho local]# cd
[root@glon_ho ~]# ls
my3306.cnf
[root@glon_ho ~]# mv my3306.cnf /data/mysql/mysql3306/
[root@glon_ho ~]# chown -R mysql:mysql /data/mysql/mysql3306/
[root@glon_ho ~]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
[root@glon_ho ~]# vim /etc/profile
...
export PATH=$PATH:/usr/local/mysql/bin
"/etc/profile" 80L, 1881C written 
[root@glon_ho ~]# source /etc/profile
[root@glon_ho ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@glon_ho ~]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
[1] 2634
[root@glon_ho ~]#
[root@glon_ho ~]# ps aux| grep mysql
mysql     2634  8.1 13.1 2616584 269924 pts/0  Sl   07:46   0:01 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf
root      2679  0.0  0.0 105368   880 pts/0    S+   07:47   0:00 grep mysql
[root@glon_ho ~]# grep 'password' /data/mysql/mysql3306/data/error.log
2017-07-03T06:43:34.915585Z 1 [Note] A temporary password is generated for root@localhost: NxJDq-a=&2tf
[root@glon_ho ~]# mysql -S /tmp/mysql3306.sock -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-15-log
Copyright (c) 2009-2017 Percona LLC and/or its affiliates
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| mysql.sys | localhost |
| root      | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> \q
Bye
[root@glon_ho ~]# cp /usr/local/mysql/lib/mysql/libjemalloc.so.1 /usr/lib/
[root@glon_ho ~]# cp /usr/local/mysql/lib/mysql/libjemalloc.so.1 /usr/lib64/
[root@glon_ho ~]# vim /data/mysql/mysql3306/my3306.cnf
...
[mysqld_safe]
#malloc-lib=/usr/local/mysql/lib/mysql/libjemalloc.so.1
malloc-lib=/usr/lib64/libjemalloc.so.1
plugin-dir = /usr/local/mysql/lib/mysql/plugin/
plugin-load=ha_tokudb.so
nice=-19
open-files-limit=65535
default-time-zone = '+8:00'
"/data/mysql/mysql3306/my3306.cnf" 158L, 4025C written
[root@glon_ho ~]# sh upds.sh
[root@glon_ho ~]#  mysqld_safe Adding '/usr/lib64/libjemalloc.so.1' to LD_PRELOAD for mysqld
2017-07-03T07:02:34.225085Z mysqld_safe Logging to '/data/mysql/mysql3306/data/error.log'.
2017-07-03T07:02:34.361730Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql3306/data
[root@glon_ho ~]# ps aux| grep mysql
root      4586  0.8  0.0 108256  1604 pts/0    S    08:02   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my3306.cnf
mysql     5622 16.8 14.6 1941052 301660 pts/0  S<l  08:02   0:01 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --plugin-dir=/usr/local/mysql/lib/mysql/plugin/ --user=mysql --log-error=/data/mysql/mysql3306/data/error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql3306/data/mysql.pid --socket=/tmp/mysql3306.sock --port=3306
root      5667  0.0  0.0 105372   892 pts/0    S+   08:02   0:00 grep mysql
[root@glon_ho ~]#
[root@glon_ho ~]# ps_tokudb_admin -S /tmp/mysql3306.sock --enable -uroot -p123456
Checking SELinux status...
INFO: SELinux is disabled.
Checking if Percona Server is running with jemalloc enabled...
INFO: Percona Server is running with jemalloc enabled.
Checking transparent huge pages status on the system...
INFO: Transparent huge pages are enabled (should be disabled).
Checking if thp-setting=never option is already set in config file...
INFO: Option thp-setting=never is not set in the config file.
      (needed only if THP is not disabled permanently on the system)
Checking TokuDB engine plugin status...
INFO: TokuDB engine plugin is not installed.
Disabling transparent huge pages for the current session...
INFO: Successfully disabled transparent huge pages for this session.
Adding thp-setting=never option into /etc/my.cnf
INFO: Successfully added thp-setting=never option into /etc/my.cnf
Installing TokuDB engine...
INFO: Successfully installed TokuDB engine plugin.
[root@glon_ho ~]# sh en.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18-15-log Percona Server (GPL), Release 15, Revision bff2cd9
Copyright (c) 2009-2017 Percona LLC and/or its affiliates
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select @@tokudb_version;
+------------------+
| @@tokudb_version |
+------------------+
| 5.7.18-15        |
+------------------+
1 row in set (0.00 sec)
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| TokuDB             | YES     | Percona TokuDB Storage Engine with Fractal Tree(tm) Technology             | YES          | YES  | YES        |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | 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       |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)
mysql> show plugins;
+-------------------------------+----------+--------------------+--------------+---------+
| Name                          | Status   | Type               | Library      | License |
+-------------------------------+----------+--------------------+--------------+---------+
| binlog                        | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| mysql_native_password         | ACTIVE   | AUTHENTICATION     | NULL         | GPL     |
| sha256_password               | ACTIVE   | AUTHENTICATION     | NULL         | GPL     |
| MEMORY                        | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| CSV                           | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| InnoDB                        | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| XTRADB_READ_VIEW              | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| XTRADB_INTERNAL_HASH_TABLES   | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| XTRADB_RSEG                   | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| XTRADB_ZIP_DICT               | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| XTRADB_ZIP_DICT_COLS          | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_TRX                    | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_LOCKS                  | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_LOCK_WAITS             | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMP                    | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMP_RESET              | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMPMEM                 | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMPMEM_RESET           | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMP_PER_INDEX          | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CMP_PER_INDEX_RESET    | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_BUFFER_PAGE            | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_BUFFER_PAGE_LRU        | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_BUFFER_POOL_STATS      | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_TEMP_TABLE_INFO        | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_METRICS                | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_DEFAULT_STOPWORD    | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_DELETED             | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_BEING_DELETED       | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_CONFIG              | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_INDEX_CACHE         | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_FT_INDEX_TABLE         | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_TABLES             | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_TABLESTATS         | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_INDEXES            | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_COLUMNS            | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_FIELDS             | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_FOREIGN            | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_FOREIGN_COLS       | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_TABLESPACES        | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_DATAFILES          | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_CHANGED_PAGES          | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| INNODB_SYS_VIRTUAL            | ACTIVE   | INFORMATION SCHEMA | NULL         | GPL     |
| PERFORMANCE_SCHEMA            | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| MRG_MYISAM                    | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| MyISAM                        | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| partition                     | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| ARCHIVE                       | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| BLACKHOLE                     | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| FEDERATED                     | DISABLED | STORAGE ENGINE     | NULL         | GPL     |
| ngram                         | ACTIVE   | FTPARSER           | NULL         | GPL     |
| TokuDB                        | ACTIVE   | STORAGE ENGINE     | ha_tokudb.so | GPL     |
| TokuDB_file_map               | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_fractal_tree_info      | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_fractal_tree_block_map | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_trx                    | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_locks                  | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_lock_waits             | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_background_job_status  | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
+-------------------------------+----------+--------------------+--------------+---------+
58 rows in set (0.00 sec)
mysql> show global variables like "%tokudb%";
+-----------------------------------------+-------------------------+
| Variable_name                           | Value                   |
+-----------------------------------------+-------------------------+
| tokudb_alter_print_error                | OFF                     |
| tokudb_analyze_delete_fraction          | 1.000000                |
| tokudb_analyze_in_background            | ON                      |
| tokudb_analyze_mode                     | TOKUDB_ANALYZE_STANDARD |
| tokudb_analyze_throttle                 | 0                       |
| tokudb_analyze_time                     | 5                       |
| tokudb_auto_analyze                     | 30                      |
| tokudb_block_size                       | 4194304                 |
| tokudb_bulk_fetch                       | ON                      |
| tokudb_cache_size                       | 1051711488              |
| tokudb_cachetable_pool_threads          | 0                       |
| tokudb_cardinality_scale_percent        | 100                     |
| tokudb_check_jemalloc                   | ON                      |
| tokudb_checkpoint_lock                  | OFF                     |
| tokudb_checkpoint_on_flush_logs         | OFF                     |
| tokudb_checkpoint_pool_threads          | 0                       |
| tokudb_checkpointing_period             | 60                      |
| tokudb_cleaner_iterations               | 5                       |
| tokudb_cleaner_period                   | 1                       |
| tokudb_client_pool_threads              | 0                       |
| tokudb_commit_sync                      | ON                      |
| tokudb_compress_buffers_before_eviction | ON                      |
| tokudb_create_index_online              | ON                      |
| tokudb_data_dir                         |                         |
| tokudb_debug                            | 0                       |
| tokudb_dir_cmd                          |                         |
| tokudb_dir_cmd_last_error               | 0                       |
| tokudb_dir_cmd_last_error_string        |                         |
| tokudb_dir_per_db                       | ON                      |
| tokudb_directio                         | OFF                     |
| tokudb_disable_hot_alter                | OFF                     |
| tokudb_disable_prefetching              | OFF                     |
| tokudb_disable_slow_alter               | OFF                     |
| tokudb_empty_scan                       | rl                      |
| tokudb_enable_partial_eviction          | ON                      |
| tokudb_fanout                           | 16                      |
| tokudb_fs_reserve_percent               | 5                       |
| tokudb_fsync_log_period                 | 0                       |
| tokudb_hide_default_row_format          | ON                      |
| tokudb_killed_time                      | 4000                    |
| tokudb_last_lock_timeout                |                         |
| tokudb_load_save_space                  | ON                      |
| tokudb_loader_memory_size               | 100000000               |
| tokudb_lock_timeout                     | 4000                    |
| tokudb_lock_timeout_debug               | 1                       |
| tokudb_log_dir                          |                         |
| tokudb_max_lock_memory                  | 131463936               |
| tokudb_optimize_index_fraction          | 1.000000                |
| tokudb_optimize_index_name              |                         |
| tokudb_optimize_throttle                | 0                       |
| tokudb_prelock_empty                    | ON                      |
| tokudb_read_block_size                  | 65536                   |
| tokudb_read_buf_size                    | 131072                  |
| tokudb_read_status_frequency            | 10000                   |
| tokudb_row_format                       | tokudb_zlib             |
| tokudb_rpl_check_readonly               | ON                      |
| tokudb_rpl_lookup_rows                  | ON                      |
| tokudb_rpl_lookup_rows_delay            | 0                       |
| tokudb_rpl_unique_checks                | ON                      |
| tokudb_rpl_unique_checks_delay          | 0                       |
| tokudb_strip_frm_data                   | OFF                     |
| tokudb_support_xa                       | ON                      |
| tokudb_tmp_dir                          |                         |
| tokudb_version                          | 5.7.18-15               |
| tokudb_write_status_frequency           | 1000                    |
+-----------------------------------------+-------------------------+
65 rows in set (0.02 sec)
mysql> \q
Bye
[root@glon_ho ~]#
[root@glon_ho ~]# vim /data/mysql/mysql3306/my3306.cnf
...
##tokuDB
#TokuDB的行模式,建议用 FAST ,如果磁盘空间很紧张,建议用 SMALL
tokudb_row_format = tokudb_fast
tokudb_cache_size = 1G
tokudb_commit_sync = 0
tokudb_directio = 1
tokudb_read_block_size = 128K
tokudb_read_buf_size = 128K
 
 
[mysqld_safe]
malloc-lib=/usr/lib64/libjemalloc.so.1
plugin-dir = /usr/local/mysql/lib/mysql/plugin/
plugin-load=ha_tokudb.so
nice=-19
open-files-limit=65535
default-time-zone = '+8:00'
"/data/mysql/mysql3306/my3306.cnf" 158L, 4009C written  
[root@glon_ho ~]# sh down.sh
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
2017-07-03T07:10:34.861225Z mysqld_safe mysqld from pid file /data/mysql/mysql3306/data/mysql.pid ended
[root@glon_ho ~]#
[root@glon_ho ~]# sh upds.sh
[root@glon_ho ~]#  mysqld_safe Adding '/usr/lib64/libjemalloc.so.1' to LD_PRELOAD for mysqld
2017-07-03T07:10:46.379879Z mysqld_safe Logging to '/data/mysql/mysql3306/data/error.log'.
2017-07-03T07:10:46.414953Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql3306/data
[root@glon_ho ~]# sh en.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-15-log Percona Server (GPL), Release 15, Revision bff2cd9
Copyright (c) 2009-2017 Percona LLC and/or its affiliates
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| TokuDB             | YES     | Percona TokuDB Storage Engine with Fractal Tree(tm) Technology             | YES          | YES  | YES        |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | 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       |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)
mysql> create database toku;
Query OK, 1 row affected (0.01 sec)
mysql> use toku
Database changed
mysql> create table t (id int, name varchar(32)) engine=tokudb;
Query OK, 0 rows affected (0.14 sec)
mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(32) DEFAULT NULL
) ENGINE=TokuDB DEFAULT CHARSET=utf8 ROW_FORMAT=TOKUDB_QUICKLZ
1 row in set (0.02 sec)
mysql> insert into t values (1,'Eason Chan'),(2,'Andy Lau');
Query OK, 2 rows affected (0.05 sec)
Records: 2  Duplicates: 0  Warnings: 0
mysql> select * from t;
+------+------------+
| id   | name       |
+------+------------+
|    1 | Eason Chan |
|    2 | Andy Lau   |
+------+------------+
2 rows in set (0.00 sec)
mysql>
mysql> create table t2 (id int, name varchar(32));
Query OK, 0 rows affected (0.05 sec)
mysql> show create table t2\G
*************************** 1. row ***************************
       Table: t2
Create Table: CREATE TABLE `t2` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> insert into t2 values (1,'Eason Chan'),(2,'Andy Lau');
Query OK, 2 rows affected (0.09 sec)
Records: 2  Duplicates: 0  Warnings: 0
mysql> select * from t2;
+------+------------+
| id   | name       |
+------+------------+
|    1 | Eason Chan |
|    2 | Andy Lau   |
+------+------------+
2 rows in set (0.00 sec)
mysql> \q
Bye
[root@glon_ho ~]#
posted @ 2017-07-04 11:11  GlonHo  阅读(2883)  评论(0编辑  收藏  举报