mysql linux installation (3) - master-slave construction

Prepare two machines:

Main: 172.19.59.50

From: 172.19.59.47

Both the master and the slave have installed the mysql server, and the version numbers are the same.

 

Let's operate the master node first:

1. Log in to the root account of the master node, and then grant permissions to the slave node (if there are multiple plex machines, execute multiple times)

mysql>GRANT REPLICATION SLAVE ON *.* TO 'backup'@'172.19.59.47' IDENTIFIED BY '123456’;

 

2. Modify the master node configuration file:

vi /etc/my.cnf

[mysqld]

#Add the following configuration after [mysqld]

server-id=1 #represents the master node id, guaranteed to be unique

log-bin=mysql-bin #Open binary log file

binlog-do-db=test #Database nodes that need to be synchronized, write multiple lines if there are multiple

binlog-ignore-db=mysql #Do not need to synchronize database nodes, write multiple lines if there are multiple

 

Then operate the slave node:

1. Log in to the slave node root account and add the master node information:

change master to master_host='172.19.59.50',master_user='test',master_password='123456',master_log_file='mysql-bin.000005',master_log_pos=120;

 

2. Modify the mysql configuration file

vi /etc/my.cnf

[mysqld]

#Add the following configuration after [mysqld]

server-id=2 #represents the slave node id, guaranteed to be unique

log-bin=mysql-bin #Open binary log file

replicate-do-db=test #Database nodes that need to be synchronized, write multiple rows if there are multiple

replicate-ignore-db=mysql #Do not need to synchronize database nodes, write multiple rows if there are multiple

#Note the difference between the last two lines and the master node.

#In addition, in order to prevent errors during master-slave synchronization, the following configuration can be added:

slave-skip-errors=1062,1053 #1062 error refers to some primary key duplicate errors

slave-skip-errors=all  #忽略所有错误

slave-skip-errors=ddl_exist_errors  #忽略DDL错吴  

#注意 slave-skip-errors 的配置一定要放在[mysqld] 下面。

 

以上配置操作完成之后,分别执行以下命令重启主节点和从节点。

service mysqld restart

 

重启完成之后,查看主从节点的状态:

在主机中,mysql>show master status;


 在从机中,mysql>show slave status\G;


 如果以下显示YES,

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

并且下面这2项和主节点的一致,表示主从配置正确

Master_Log_File: mysql-bin.000003

Read_Master_Log_Pos: 460

 

以上表示mysql主从配置成功,下面可以验证一下。

在主节点上创建一个测试表test,然后添加一条数据,看从节点上是否能收到。

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326303014&siteId=291194637