Skip to content
/ msc Public

An Apache licensed MySQL/MariaDB Erlang/OTP 26+ client that includes replication

License

Notifications You must be signed in to change notification settings

shortishly/msc

Repository files navigation


Test Coverage edoc Erlang/OTP 26+ Apache-2.0

What is msc?

An Apache licensed MySQL/MariaDB Erlang/OTP 26+ client that includes replication.

Start a local mysql:

./bin/up

Build the client with OTP 26+:

make

Run an Erlang/OTP 26+ with the client:

make shell

Connect to the database, run a very simple query:

URI = <<"mysql://root:secret@localhost:3306/test">>.
{ok, Supervisor} = msc_connections_sup:start_child(URI).
MM = msc_sup:get_child_pid(Supervisor, mm).
msc_mm_sync:query(#{server_ref => MM, query => <<"select 2 + 2">>}).

{[#{decimals => 0,flags => 129,name => <<"2 + 2">>,
    table => <<>>,type => 8,character_set => 63,
    reserved0 => <<0,0>>,
    catalog => <<"def">>,schema => <<>>,org_table => <<>>,
    org_name => <<>>,length_of_fixed_length_fields => 12,
    column_length => 3}],
 [[<<"4">>]]}

Replicate data into ETS:

URI = <<"mysql://root:secret@localhost:3306/test">>.
{ok, Supervisor} = msc_connections_sup:start_child(URI).
MM = msc_sup:get_child_pid(Supervisor, mm).
SQL = <<"SET @master_binlog_checksum = @@global.binlog_checksum, @source_binlog_checksum = @@global.binlog_checksum">>.
msc_mm_sync:query(#{server_ref => MM, query => SQL}).

{ok, _} = msc_binlog_ets:start().
msc_mm_sync:binlog_dump(#{server_ref => MM, call_back => msc_binlog_ets}).

Check some of the example tables that have been replicated:

ets:i(test_t7).