RocksDB是FaceBook基于Google开源的LevelDB实现的,使用LSM(Log-Structure Merge)树来存储数据。Facebook开发工程师对RocksDB进行了大量的开发,使其符合MySQL的插件式存储引擎框架的要求,移植到了MySQL上,并称之为MyRocks。MyRocks支持基于SQL的数据读写、锁机制、MVCC、事务、主从复制等MySQL绝大部分功能特性。从使用习惯考虑,使用MyRocks还是使用MySQL/InnoDB并没有多大区别。

MyRocks Docker images

拉取MyRocks镜像

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
> docker pull perconalab/myrocks
Using default tag: latest
latest: Pulling from perconalab/myrocks
3d8673bd162a: Pull complete
fa8bf89ff42f: Pull complete
ec71424809cd: Pull complete
02bf65cc65e8: Pull complete
7830e17ba28b: Pull complete
Digest: sha256:614dbcef6bb7eb27bc5e28ffaa7b287c4008ca296f956554a6b4a8f4de6aebdf
Status: Downloaded newer image for perconalab/myrocks:latest
docker.io/perconalab/myrocks:latest

查看镜像

1
2
3
> docker images
REPOSITORY           TAG     IMAGE ID       CREATED         SIZE
perconalab/myrocks   latest  3bdeb1d79649   4 years ago     2.67GB

该镜像太久没有更新,建议使用最新版本重新生成,按照官网安装

运行镜像

1
2
3
4
5
> docker run -d --name myr -P  perconalab/myrocks
e57a474552c5bc1a74e6181ba40ed17c0207134fcd5ffb2f682ec4972d4dff97
> docker ps
CONTAINER ID   IMAGE                COMMAND             CREATED         STATUS         PORTS                     NAMES
e57a474552c5   perconalab/myrocks   "/entrypoint.sh "   5 seconds ago   Up 3 seconds   0.0.0.0:55000->3306/tcp   myr

登录镜像,连接数据库

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
> docker exec -it myr /bin/bash
[root@e57a474552c5 /]# /usr/local/mysql/bin/mysql -h127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.27 Source distribution

Copyright (c) 2000, 2015, 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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> show engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ROCKSDB    | DEFAULT | RocksDB storage engine                                         | YES          | YES  | YES        |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM     | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | 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         |
| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| InnoDB     | NO      | Supports transactions, row-level locking, and foreign keys     | NULL         | NULL | NULL       |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

mysql> CREATE TABLE `linktable` (
    ->   `id1` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->   `id1_type` int(10) unsigned NOT NULL DEFAULT '0',
    ->   `id2` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->   `id2_type` int(10) unsigned NOT NULL DEFAULT '0',
    ->   `link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->   `visibility` tinyint(3) NOT NULL DEFAULT '0',
    ->   `data` varchar(255) NOT NULL DEFAULT '',
    ->   `time` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->   `version` int(11) unsigned NOT NULL DEFAULT '0',
    -> PRIMARY KEY (link_type, `id1`,`id2`) COMMENT 'cf_link_pk',
    -> KEY `id1_type` (`id1`,`link_type`,`visibility`,`time`,`version`,`data`) COMMENT 'rev:cf_link_id1_type'
    -> ) ENGINE=RocksDB DEFAULT COLLATE=latin1_bin;
Query OK, 0 rows affected (0.02 sec)

mysql> show tables in test;
+----------------+
| Tables_in_test |
+----------------+
| linktable      |
+----------------+
1 row in set (0.00 sec)

mysql> desc linktable;
+------------+---------------------+------+-----+---------+-------+
| Field      | Type                | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+-------+
| id1        | bigint(20) unsigned | NO   | PRI | 0       |       |
| id1_type   | int(10) unsigned    | NO   |     | 0       |       |
| id2        | bigint(20) unsigned | NO   | PRI | 0       |       |
| id2_type   | int(10) unsigned    | NO   |     | 0       |       |
| link_type  | bigint(20) unsigned | NO   | PRI | 0       |       |
| visibility | tinyint(3)          | NO   |     | 0       |       |
| data       | varchar(255)        | NO   |     |         |       |
| time       | bigint(20) unsigned | NO   |     | 0       |       |
| version    | int(11) unsigned    | NO   |     | 0       |       |
+------------+---------------------+------+-----+---------+-------+
9 rows in set (0.01 sec)

参考