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
This commit is contained in:
parent
db7b4fb073
commit
e641974f06
@ -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;"
|
||||
|
Loading…
Reference in New Issue
Block a user