MySQL Replication
Check
SHOW MASTER STATUS\G
SHOW REPLICA HOSTS;
SHOW REPLICA STATUS\G
SELECT @@SERVER_ID;
Must be different for each instance in the replication topologySELECT @@INNODB_FLUSH_LOG_AT_TRX_COMMIT;
Recommended Setting: 1SELECT @@SYNC_BINLOG;
Recommended Setting: 1SELECT @@SKIP_NETWORKING;
Must be 0 for replication to workLost Master
If you just have 1 replica then this should be enough...
STOP REPLICA;
If you have more than 1 replica.. On the new Master to be...
STOP REPLICA;
RESET BINARY LOGS AND GTIDS;
On the other Slaves...
STOP REPLICA;
CHANGE REPLICATION SOURCE TO SOURCE_HOST='MyNewMaster';
START REPLICA;
Binary Log File Position Based Replication
TODO
Replication with Global Transaction Identifiers
TODO
MySQL Master-Master Replication
Master-master replication (with load balancer) introduces the possibility that two or more servers can replicate concurrent changes to each other. To prevent key conflicts by using the auto_increment_offset and auto_increment_increment configuration variables, to ensure AUTO_INCREMENT values will be unique to each server.
auto-increment-increment = 2
auto-increment-offset = 2 or 1
Appropriate load balancers would be:
keepalived
haproxy
heartbeat + mon
mysql-proxy
F5 Big-IP
java conection pools
Limitations
the safest option is to use one server as active for both writes and reads, second will be treated as standby
no synchronous replication - if application can handle replication lag between servers it is possible to scale out reads
difficult to extend - this is only 2 server setup
Bibliography
GTIDshttps://dev.mysql.com/doc/refman/8.0/en/replication-gtids-failover.html
HAProxyhttp://www.haproxy.org/
RESEThttps://dev.mysql.com/doc/refman/8.0/en/reset.html
Lost Masterhttps://serverfault.com/questions/303669/how-to-actually-use-mysql-slave-as-soon-the-master-is-failover-or-got-burnthttps://dev.mysql.com/doc/refman/8.4/en/replication-solutions-switch.htmlhttps://dev.mysql.com/doc/mysql-replication-excerpt/5.7/en/replication-administration-pausing.html