1. Basic Steps for copying
It takes only three steps to create a simple copy.
- Configure a server as the Master database, that is, the Master database.
- Configure another server as the slave database, that is, the slave database.
- Connect the slave database to the master database.
2. Configure the master database
To configure the server as the master database, make sure that the server has an active binary log and a unique server ID. This binary log stores all data changes in the master database, the server ID is used to identify the server separately. To create a binary log and a server ID, stop the server and configure the my. cnf configuration file. The operations on the master database mainly include the configuration of binary log files and the addition of accounts for replication;
2.1 configure the binary log file
I added the following three lines to my master database configuration file:
- Log-bin = master-bin
- Log-bin-Index= Master-bin.Index
- Server-id = 1
After I added these three lines, I restarted the service and found two more files under the Data Directory: master-bin.000001, master-bin.index. These two files play a major role in master-slave synchronization.
In fact, in addition to these three configurations, you can also add some other configurations, such as binlog-ignore-db configuration databases that do not need to be synchronized.
2.2 Add a duplicate account
Create account: create user repl_user; Grant Account replication permission: grant replication slave on *. * to repl_user identified by 'pwd ';