Skip to content

calii23/mysql-replication-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL replication guard

This tool can be used to verify the integrity of a MySQL replication. There is a command to set up the replication. After the replication is set up, it can be verified that the content of the tables are equivalent on both sides.

Installation

npm install -g mysql-replication-guard

or with yarn:

yarn global add mysql-replication-guard

Config file

A config file must be created. It can look like that for instance:

{
  "master": {
    "host": "master-host",
    "user": "replication_guard",
    "password": "<some password>"
  },
  "slave": {
    "host": "slave-host",
    "user": "replication_guard",
    "password": "<some password>"
  },
  "slaveMasterConnection": {
    "host": "master-host",
    "user": "slave_user",
    "password": "<some password>"
  },
  "databaseName": "<db name>",
  "tables": "all",
  "replicationChannel": "production",
  "mysqlTool": "/usr/bin/mysql",
  "dumpTool": "/usr/bin/mysqldump",
  "mail": {
    "smtp": {
      "host": "smtp.example.com",
      "auth": {
        "user": "system@example.com",
        "pass": "<some password>"
      },
      "port": 587
    },
    "to": {
      "address": "admin@example.com",
      "name": "Admin"
    },
    "from": {
      "address": "system@example.com",
      "name": "MySQL replication guard"
    },
    "subject": "MySQL replication guard event"
  }
}

Details about the schema of the config file can be found in dist/config/schema.json.

Mail

A mail property can be provided optionally. When provided, an E-Mail will be send with the given configuration when an error occurs, or a data inconsistency was detected (even if it could be fixed).

The property can be omitted, in that case no E-Mails will be sent at all.

MySQL Permission

The script needs the following permissions to the database:

Master

CREATE USER replication_guard@localhost IDENTIFIED BY '<some password>';
GRANT SELECT, LOCK TABLES ON database.* TO replication_guard@localhost;
GRANT SUPER, RELOAD ON *.* TO replication_guard@localhost;

Slave

CREATE USER replication_guard@localhost IDENTIFIED BY '<some password>';
GRANT RELOAD, SUPER ON *.* TO replication_guard@localhost;
GRANT