diff options
author | ben smith <polynomial@users.noreply.github.com> | 2016-07-20 17:15:55 -0700 |
---|---|---|
committer | Rok Garbas <rok@garbas.si> | 2016-07-21 02:15:55 +0200 |
commit | e641974f0671ccbff644e387a76ba5982e5f9dc3 (patch) | |
tree | e171b193d208e5e952392b85803bf3fe9f997fae /nixos/modules | |
parent | db7b4fb073d25832ecc4e216d410ad2dde153c43 (diff) | |
download | nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar.gz nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar.bz2 nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar.lz nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar.xz nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.tar.zst nixlib-e641974f0671ccbff644e387a76ba5982e5f9dc3.zip |
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
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/services/databases/mysql.nix | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix index efc52e917b00..60c6b22e0595 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;" |