MySQL replication is among the top features of MySQL. In replication data is replicated from one MySQL Server (also knows as Master) to another MySQL Server(also known as Slave). MySQL Binlog Events is a set of libraries which work on top of replication and open directions for myriad of use cases like extracting data from binary log files, building application to support heterogeneous replication, filtering events from binary log files and much more.
All this in REAL TIME .
INTRODUCTION
I have already defined what MySQL Binlog Events is, to deliver on any of the above use-cases, you first need to read the event from the binary log. This can be done using two types of transports:
1) TCP transport: Here your application will connect to an online MySQL Server and receive events as and when they occur.
2) File transport: As the name suggests the application will connect to an already existing file and read the events from it.
In the MySQL framework we always receive one event at a time irrespective of the transport , after the connection is established, we will start reading the events from the binary log files and hold the information in a buffer.
To do something useful with the event it needs to be decoded, and then the relevant information will be stored or processed based on the requirements of the application.
Event processing can be implemented in a very sophisticated manner using the content handlers in MySQL Binlog Events which are designed specifically for that purpose.
The set of libraries in MySQL Binlog Events are all C++ libraries, this is a brief introduction of them
– libmysqlstream -> Methods related to connecting with the transport and receiving the buffer from the connection and processing the events using content handlers.
– libbinlogevents -> Methods for decoding the events after receiving them from any of the transports the application is connected via.
GETTING AND COMPILING THE SOURCE CODE
You can get a copy of source code from labs.mysql.com, select MySQL Binlog Events 1.0.0 from the drop down menu. After selecting that you will get an option to download either the source code or the binaries, for respective platforms.
If downloading the source code these are some prerequisite which you need to have on your machine in order to compile the source code successfully.
- MySQL binaries of 5.7.6 or greater
- To link to the libmysqlclient library.
- The header files in the include directory are also used.
- MySQL Source code of the same version as of binaries
- To get few header files which are not part of the binaries and are being used
- CMake 2.6 or greater
- GCC 4.6.3 or greater
Steps for compiling MySQL Binlog Events source:
- Run the ‘cmake’ command on the parent directory of the MySQL Binlog Events source. This will generate the necessary Makefiles. Options to set while running CMake.
- Make sure to set cmake option ENABLE_DOWNLOADS=1; which will install Google Test which is required to run the unit
tests. - The option MYSQLCLIENT_STATIC_LINKING:BOOL=TRUE; will make the linking with libmysqlclient static
- You need to point to the MySQL Binary directory in order to make the library libmysqlclient and other header files
visible, this is done by setting MYSQL_DIR={parent directory of the MySQL Binaries}. - As I have already discussed that, we also need to include header files from the MySQL Source code, for that you need
to do MYSQL_SOURCE_INCLUDE_DIR={Parent directory of MYSQL source}/include
the full command for doing CMake iscmake . -DMYSQLCLIENT_STATIC_LINKING:BOOL=TRUE
-DMYSQL_DIR= {Parent directory of MySQL binary}
-DMYSQL_SOURCE_INCLUDE_DIR={Parent directory of MYSQL source}
-DENABLE_DOWNLOADS=1Run the ‘cmake’ command on the parent directory of the MySQL Binlog Events source. This will generate the necessary Makefiles. Options to set while running CMake.
- Make sure to set cmake option ENABLE_DOWNLOADS=1; which will install Google Test which is required to run the unit
- Run make and make install to build and install, this will create the libraries libmysqlstream and libbinlogevents
That will be all, you are now ready to create your own application using MySQL Binlog Events.
For more details about the use cases and how to create a small application using MySQL Binlog Events refer to the second blog in this series.