Home > Database > Mysql Tutorial > Practical mysql cluster construction (2)--implementing mysql database master-slave replication

Practical mysql cluster construction (2)--implementing mysql database master-slave replication

黄舟
Release: 2017-02-28 13:29:41
Original
1680 people have browsed it

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
Copy after login

2. Restart mysql

# /etc/init.d/mysqld restart
Copy after login

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;
Copy after login

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
Copy after login

3. Import the master_16-09-12.sql file into the slave library

# mysql -uroot -p < master_16-09-12.sql
Copy after login

4. Configure the slave server slave

mysql> change master to        
master_host="主服务器IP",       
master_user="mysql",       
master_password="mysql";
Copy after login

5. Start the slave server slave

    mysql> start slave;
      mysql>quit;
      #/etc/init.d/mysqld restart
Copy after login

6. Check the slave server status
##

mysql> show slave status\G;
Copy after login

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 (m.sbmmt.com)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template