Home >Backend Development >PHP Tutorial >Optimizing Availability with MySQL Built-in Replication (4)_PHP Tutorial
Step 3: Create a mutual master-slave relationship
First, in the my.cnf file on machine B, add "log-bin" to the [mysqld] section, then restart mysqld, and then create a command that can be executed on it For the user account of the replication function, use:
GRANT FILE ON *.* TO replicate@10.1.1.1 IDENTIFIED BY "password";
Run the "FLUSH PRIVILEGES" command on machine B to load it after adding the replication user Create a new authorization table, then go back to machine A and add the following lines to its "my.cnf":
master-host=10.1.1.2
master-user=replicate
master-password =password
After restarting the service program of machine A, now we have a mutual master-slave relationship between machine A and machine B. No matter which server a record is updated or a record is inserted, it will be copied to the other server. Note: I'm not sure how quickly a standby machine can merge binary log changes, so using this method to load balance insert or update statements may not be a good idea.