From e641974f0671ccbff644e387a76ba5982e5f9dc3 Mon Sep 17 00:00:00 2001 From: ben smith Date: Wed, 20 Jul 2016 17:15:55 -0700 Subject: [PATCH] MySQL Replication (that actually works) (#7198) Improves replication functionality by: * adding slaveHost on the 'master' role * adds slave user to master with replication only permissions --- nixos/modules/services/databases/mysql.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix index efc52e917b0..60c6b22e059 100644 --- a/nixos/modules/services/databases/mysql.nix +++ b/nixos/modules/services/databases/mysql.nix @@ -128,6 +128,10 @@ in description = "Hostname of the MySQL master server"; }; + slaveHost = mkOption { + description = "Hostname of the MySQL slave server"; + }; + masterUser = mkOption { description = "Username of the MySQL replication user"; }; @@ -231,10 +235,20 @@ in fi '') cfg.initialDatabases} - ${optionalString (cfg.replication.role == "slave" && atLeast55) + ${optionalString (cfg.replication.role == "master" && atLeast55) '' # Set up the replication master + ( echo "use mysql;" + echo "GRANT REPLICATION SLAVE ON *.* TO '${cfg.replication.masterUser}'@'${cfg.replication.slaveHost}';" + echo "update user set Password=password('${cfg.replication.masterPassword}') where User='${cfg.replication.masterUser}';" + ) | ${mysql}/bin/mysql -u root -N + ''} + + ${optionalString (cfg.replication.role == "slave" && atLeast55) + '' + # Set up the replication slave + ( echo "stop slave;" echo "change master to master_host='${cfg.replication.masterHost}', master_user='${cfg.replication.masterUser}', master_password='${cfg.replication.masterPassword}';" echo "start slave;"