Overview#
Master-slave replication refers to the process of transferring DDL and DML operations from the master database to the slave server through binary logs (binlog), and then re-executing these logs on the slave, also known as redo, to keep the data in sync between the master and slave.
Advantages:
- In case of master failure, it can switch to the slave.
- Read-write separation.
- The slave can perform backups, and can still read even with a global lock.
Principle#
Process:
- When the master processes a transaction commit, it records data changes (row or statement - DDL, DML) to the binary log file (binlog).
- The slave reads the master’s binary log file (binlog) and writes it to the slave's relay log.
- The slave redoes the events in the relay log to achieve consistency between master and slave.
Setup#
Server Configuration#
Master Configuration#
Slave Configuration#
Read-only applies only to ordinary users; users with super privileges can still perform insert, delete, and update operations. Super privileges can be disabled by setting super-read-only = 1 or super_read_only = 1.
This article was synchronized and updated to xLog by Mix Space. The original link is https://blog.0xling.cyou/posts/mysql/mysql-4