README.md 3.79 KB
Newer Older
1
# MySQL slave replication daemon for Tarantool
GeorgyKirichenko's avatar
GeorgyKirichenko committed
2
3
----------------------------------------------
Key features:
4
5
6
7
8
9
10
11
* Listens to a MySQL server as a replication client and translates incoming
replication events into Tarantool space operations.
* Handles a mapping between MySQL tables and Tarantool spaces.

>**Note**:
MySQL binary log should be in the row-based format.
Will not work with a MariaDB master.
Tested with MySQL 5.6 and lower.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
12
13
Not tested with MySQL 5.7 with new replication protocol improvements.

14
[About Tarantool](http://tarantool.org)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
15

16
## <a name="contents"></a>Contents
GeorgyKirichenko's avatar
GeorgyKirichenko committed
17
----------
18
19
20
* [Compilation and installation](#compilation-and-installation)
* [MySQL configuration](#mysql-configuration)
  * [Build from source](#build-from-source)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
21
* [Tarantool configuration](#tarantool-configuration)
22
* [Replicator configuration](#replicator-configuration)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
23
24
  * [Mappings](#mappings)

25
## <a name="compilation-and-installation"></a>Compilation and installation
GeorgyKirichenko's avatar
GeorgyKirichenko committed
26
27
--------------------------

28
29
### <a name="build-from-source"></a>Build from source

GeorgyKirichenko's avatar
GeorgyKirichenko committed
30
31
32
33
34
35
36
37
 ```
 bash
 git clone https://github.com/tarantool/mysql-tarantool-replication.git mysql_tarantool-replication
 cd mysql-tarantool-replication
 git submodule update --init --recursive
 cmake .
 make
 ```
GeorgyKirichenko's avatar
GeorgyKirichenko committed
38

39
[Back to contents](#contents)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
40

41
## <a name="mysql-configuration"></a>MySQL configuration
GeorgyKirichenko's avatar
GeorgyKirichenko committed
42
43
---------------------

44
45
1. Set the `binlog_format` to `ROW`.<br>
That can be done by editing the MySQL configuration file at `/etc/mysql/my.cnf`:
GeorgyKirichenko's avatar
GeorgyKirichenko committed
46
47
48
 ```
 binlog_format = ROW
 ```
49
50

2. Create a user for replication, for example:
GeorgyKirichenko's avatar
GeorgyKirichenko committed
51
52
53
 ```
 CREATE USER <username>@'<host>' IDENTIFIED BY '<password>';
 ```
54
55

3. Grant replication privileges to the new user:
GeorgyKirichenko's avatar
GeorgyKirichenko committed
56
57
58
59
60
 ```
 GRANT REPLICATION CLIENT ON '<db>'.'<table>' TO <username>@'<domain>';
 GRANT REPLICATION SLAVE ON '<db>'.'<table>' TO <username>@'<domain>';
 GRANT SELECT ON '<db>'.'<table>' TO <username>@'<domain>';
 ```
61
62
63
>**Note**: you can use an asterisk (\*) as a wildcard instead of specifying a database and a table.

4. Flush the changes:
GeorgyKirichenko's avatar
GeorgyKirichenko committed
64
65
66
 ```
 FLUSH PRIVILEGES
 ```
GeorgyKirichenko's avatar
GeorgyKirichenko committed
67

68
[Back to contents](#contents)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
69

70
## <a name="tarantool-configuration"></a>Tarantool configuration
GeorgyKirichenko's avatar
GeorgyKirichenko committed
71
72
--------------------------

73
74
75
76
1. Create one space for replication daemon purposes.<br>
This space will store the current replication state.

2. Create more spaces to store replicated data.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
77

78
3. Create a user for the replication daemon and enable read/write operations on
GeorgyKirichenko's avatar
GeorgyKirichenko committed
79
80
target spaces.

81
[Back to contents](#contents)
GeorgyKirichenko's avatar
GeorgyKirichenko committed
82

83
## <a name="replicator-configuration"></a>Replicator configuration
GeorgyKirichenko's avatar
GeorgyKirichenko committed
84
85
---------------------------

86
87
88
1. Set up MySQL connection parameters: `host`, `port`, `login` and `password`.

2. Set up Tarantool connection options: `host`, `port`, `login` and `password`.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
89

90
91
3. Set `binlog_pos_space` to the space id created for the replication state and
`binlog_pos_key` to identify the corresponding tuple in a given space.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
92

93
### <a name="mappings"></a>Mappings
GeorgyKirichenko's avatar
GeorgyKirichenko committed
94
95
------------

96
97
98
Replicator can map MySQL tables to one or more Tarantool spaces.
Each mapping item contains the names of a database and a table, a list of replicated columns,
a space id (if the space id is the same as for the previous item, it is left blank) and space
GeorgyKirichenko's avatar
GeorgyKirichenko committed
99
100
key fields numbers.

101
102
103
104
105
106
107
Multiple MySQL tables can be mapped to one Tarantool space, and the first
table in the mapping is primary. In this case, each subsequent mapping item adds
its columns to the end of the list of replicated columns for the space. When
a non-primary table deletes its row, the corresponding fields in the tuple are
reset to `NULL`. When a row is inserted into a non-primary table, the
corresponding tuple is updated if it already exists or inserted if not, and all the fields
before the field mapping are set to `NULL`.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
108

109
110
>**Note**: the configuration file contains a **Spaces** section, where you can set default values
for tuples - for example, for indexed fields.
GeorgyKirichenko's avatar
GeorgyKirichenko committed
111

112
[Back to contents](#contents)