ArticleDirectory
-
- Configure master
-
- Configure slave
-
- Connect master and slave
High Availability MySQL p10
MySQL master-slave Replication
MySQL replication is often used in the following environments:
1. Avoid disaster through hot backup
2. Generate Reports
Using the slave server to generate reports can greatly reduce the load on the master server.
3 debugging and auditing
For example, check whether some queries have performance problems and whether the server is not synchronized due to a slot query.
Basic Steps for MySQL Replication
1. configure a server as the master.
2. configure a server as slave.
3. Connect the slave to the master.
Unless you plan to copy from the very beginning and the configuration in the my. conf file is correct, steps 1 and 2 require that each server be restarted.
Configure master
Add configuration options to my. conf to configure master
[Mysqld] user=Mysqlpid-File=/Var/run/mysqld/Mysqld. pidsocket=/Var/run/mysqld/Mysqld. sockport= 3306Basedir=/Usrdatadir=/Var/lib/Mysqltmpdir=/TMPLog-Bin = Master-BINLOG-bin-Index = master-bin.indexserver-id = 1
Create a copy user on the master
Master>Create user repl_user; query OK,0 rows affected (0.00Sec) Master> Grant replication slave on *.*To repl_user identified by 'xy'; query OK,0 rows affected( 0.00 Sec)
Configure slave
Add options to the my. conf file to configure slave
[Mysqld] user=Mysqlpid-File=/Var/run/mysqld/Mysqld. pidsocket=/Var/run/mysqld/Mysqld. sockport= 3306Basedir=/Usrdatadir=/Var/lib/Mysqltmpdir=/TMPServer-ID = 2relay-log-index = slave-relay-bin.indexrelay-log = slave-relay-bin
Connect master and slave
Slave>Change master-> Master_host ="Master-1",-> Master_port = 3306,-> mcster_user ='Repl _ user ',-> Mast_password ='Xytime'; query OK,0 rows affected (0.00Sec) slave> Start slave;