MySQL master-slave replication configuration

Let's talk about my environment first, two Ubuntu14 virtual machines, the ip addresses are 192.168.176.150 (master) and 192.168.176.151 (slave). mysql version 5.5.49.

 

After MySQL is installed, you can start configuring master-slave replication.

Start with master-192.168.176.150 first.

1. First create an account, such as username backup, password 1234. This account is used by the slave machine to connect to the master, and then retrieve the bin log.

2. Connect to MySQL, mysql -u root -p.

3. Grant the permission of replication slave to the account created in step 1. The username and password will be stored in master.info

mysql > GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* 
TO backup@’192.168.176.151 
IDENTIFIED BY ‘1234’;

4. Open my.cnf and add the following values ​​to the configuration file:

server-id=150
log-bin=mysql-bin #This must be present, but the value can remain unchanged

5. Restart the master

6. Run show master status

mysql>show master status.

Normally, a table will be output, and there are two important columns in it, one is File and the other is position. The name of the file needs to be specified when configuring the slave later, because this is the file name of the log that the slave wants to get from the master. The postion is synced from that location. It also needs to be specified when configuring the slave.

 

Configure salve:

1. Modify my.cnf

log_bin           = mysql-bin
server_id         = 151

Note that server_id is required, but log_bin is optional. But if the slave is also the master of another machine, then this is a required option.

2. Start slave

mysql>change master to master_host='192.168.176.150',master_user='backup',master_password='1234',
         master_log_file='mysql-bin.000001',master_log_pos=278;

3. Start slave

mysql>start slave;

4. You can view the slave status with show slave status

mysql>show slave status\G; #Note that it is a capital G, in this way, the typesetting of the result is vertical

 

Note: The Slave_IO and Slave_SQL processes must be running normally, that is, the YES state. In addition, you can view Slave_IO_State, which should be waiting for the master to send the event, that is, Waiting for master to send event

5. Test, insert a piece of data into a table of the master to see if it will be synchronized to the slave table.

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326994911&siteId=291194637