Home >Database >Mysql Tutorial >Practical mysql cluster construction (2)--implementing mysql database master-slave replication
Following the previous article "Practical mysql cluster construction (1)--Binary installation of mysql-5.6 under centos7", this article introduces how the main database server backs up data to another server in the form of log files. server, thus realizing master-slave replication of the database and achieving safe backup of data.
For main database operations:
1. Turn on the log-bin function on the master:
# vi /etc/my.cnf 添加如下内容: log_bin=mysql-bin server_id =1
2. Restart mysql
# /etc/init.d/mysqld restart
3. Log in to mysql to create an account on the master server and authorize the slave function
#mysql –uroot –p mysql> grant replication slave on *.* to 'mysql'@'%' identified by 'mysql'; mysql> flush priviliges; mysql> flush tables with read lock;
Of course, if data exists in both the master and slave databases before this operation, the database can be backed up as a whole. The backup process is as follows:
1, Add the mysqldump command to /usr/bin
ln - s /application/mysql/bin/mysqldump /usr/bin/
2. Use the mysqldump command to back up the master server database:
# mysqldump -uroot -p -A --master-data=1 > /tmp/master_16-09-12.sql
3. Backup completed, restore Write operation:
# mysql> unlock tables;
Operation from the database
1. Stop slave synchronization operation
mysql> stop slave;
2 , Modify the configuration file of the slave library
# vi /etc/my.cnf log_bin=mysql-bin server_id = 2
3. Import the master_16-09-12.sql file into the slave library
# mysql -uroot -p < master_16-09-12.sql
4. Configure the slave server slave
mysql> change master to master_host="主服务器IP", master_user="mysql", master_password="mysql";
5. Start the slave server slave
mysql> start slave; mysql>quit; #/etc/init.d/mysqld restart
6. Check the slave server status
##
mysql> show slave status\G;
If the following content appears, the configuration is successful:
## This is implemented by a virtual machine clon # master and slave have equal MySQL server UUIDs Solution
This is because the entire data directory of the database is also copied during the server copy process, so there is an auto.cnf file in it. This file stores the database uuid. The uuid of each database should be If it is different, just modify the uuid.
The above is the actual mysql cluster construction (2) - the content of realizing master-slave replication of mysql database. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!