MySQL Master-slave replication
background:
MySQL can achieve master-slave replication, after learning the MySQL master-slave replication, some how to record the master-slave copy process, for later review use.
Prepare:
There is a need to do some preparatory work before MySQL master-slave replication:
1. Synchronization Time
The time of the master slave server needs to be synchronized, otherwise it will be problematic.
Command: ntpdate IP (ntpdate command requires first installation of ntpdate)
2. Consistent version
The MySQL service from the master needs to be version consistent, or the version from the server is higher than the primary server.
Master-slave replication:
Step 1, install the MySQL service
Yum install mysql-server MySQL
If it is CENTOS7 version: Yum install Mariadb-server mariadb (7 on the base source has been replaced with MARIADB, but we use the same way as MySQL)
Step 2, configure the master server
1) Edit the master server configuration file/etc/my.cnf
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/13/0581887069e16c4ca84d546f59500fcb.png "title=" 1.png " alt= "0581887069e16c4ca84d546f59500fcb.png"/>
PS: Note The log file permissions issues, modify the owner of the Bin_log and belong to the group MySQL; command: Chown mysql.mysql/app/bin_log
2) Start the service and add the account number required for master-slave replication
Centos6:service mysqld Start
centos7:systemctl start mariadb
Add an account for use from the server
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/13/feedea3f67215405df199e905c906850.png "title=" 2.png " alt= "Feedea3f67215405df199e905c906850.png"/>
3) View the primary server log file and location
650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/13/fe4c7cb7a2f683df1cedd1e640692638.png "title=" 6.png " alt= "Fe4c7cb7a2f683df1cedd1e640692638.png"/>
Step 3, configure the slave server
1) Edit the configuration file
650) this.width=650; "src=" Https://s4.51cto.com/oss/201711/13/4ebb649900dcac740d4cb3cf0f6d8e8d.png "title=" 3.png " alt= "4ebb649900dcac740d4cb3cf0f6d8e8d.png"/>
Read_only=on is read-only meaning, it is not allowed to write data from the database, if it can write the data then lost its existence meaning
2) Start the service and add the primary server
Start Services: Service MySQL Start
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/13/d9277f7f332590b0e13d9d4003020a87.png "title=" 5.png " alt= "D9277f7f332590b0e13d9d4003020a87.png"/>
PS: Be sure to note where the primary service binary log version is, and synchronize with the latest binary files.
Step 4, test
1) Create a database on the primary database server
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/13/4b3e23bb041d2d67af8ab21b65054dae.png "title=" 7.png " alt= "4b3e23bb041d2d67af8ab21b65054dae.png"/>
2) When viewing from MySQL from the server to build the created database
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/13/455ba89aeef3b8bfaf2995538d222265.png "title=" 8.png " alt= "455ba89aeef3b8bfaf2995538d222265.png"/>
The master-slave replication to this MySQL has been completed.
MySQL Master-slave replication