MySQL5.7 master-slave configuration example analysis

MySQL5.7 master-slave configuration example analysis

MySQL5.7 master-slave configuration implementation method, the specific contents are as follows

Installation environment:

Master: 10.211.55.11, Redhat6.5, MySQL5.7.12
Slave: 10.211.55.12, Redhat6.5, MySQL5.7.12

Master's my.cnf configuration:

Slave's my.cnf configuration:

You can specify which databases need to be replicated and which do not need to be replicated. For example, in my my.cnf configuration, all the commented-out contents are replicated by default. After modifying the my.cnf configuration file, restart the MySQL service on both machines: service mysqld restart. The following operations are more important:
mysql configuration of the master machine

1. Log in with mysql -u root -p;
2. Execute the following command, which means that the root copy permission and File permission will be granted to 10.211.55.12. Of course, you also need to create another user to operate, which does not have to be root. 123456 represents the password.

GRANT FILE ON *.* TO 'root'@'10.211.55.12' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.211.55.12' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

3. Execute the show master status command, as shown in the figure:

這里寫圖片描述

Slave machine mysql configuration

1. Log in with mysql -u root -p;
2. Execute the following instructions in sequence:

mysql> stop slave;
mysql> change master to master_host='10.211.55.11',master_user='root',master_password='123456',master_log_file='mysql-bin.000003', master_log_pos=154;
mysql> start slave;

Notice:
The values ​​in master_log_file and master_log_pos must correspond to the values ​​in the show master status result of the Master machine (as shown above).

3. Check the slave status, show slave status\G; Note that the "\G" here is to display the formatted result. If there is no error, the slave status result is as shown in the figure:

test:

Create a database in Master:

mysql> create database test;
mysql> create table t1 (id int,name varchar(200),createtime timestamp,key(id));
mysql> insert into t1 values ​​(1,'aa',now());
mysql> insert into t1 values ​​(3,'bb',now());

After completing the above operations, switch to the Salve machine to see if it is synchronized. If nothing goes wrong, it should be synchronized immediately.
My machine shows the following:

這里寫圖片描述

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL master-slave configuration study notes
  • Record the whole process of MySQL master-slave configuration based on Linux
  • Docker mysql master-slave configuration details and examples
  • A brief note on the MySQL master-slave configuration solution
  • Sharing of the master-slave configuration method of MySQL database
  • Mysql implements master-slave configuration and multi-master-multi-slave configuration

<<:  How to use dd command in Linux without destroying the disk

>>:  How to use localStorage in JavaScript

Recommend

Detailed steps to install CentOS7 system on VMWare virtual machine

Pre-installation work: Make sure vmware workstati...

Webpack builds scaffolding to package TypeScript code

Create a folder Directory structure: dabaots Init...

How to use the Linux nl command

1. Command Introduction nl (Number of Lines) adds...

Mysql GTID Mha configuration method

Gtid + Mha + Binlog server configuration: 1: Test...

How to create a MySQL database and support Chinese characters

Let's first look at the MySQL official docume...

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

Do you know how to use mock in vue project?

Table of contents first step: The second step is ...

Tutorial analysis of quick installation of mysql5.7 based on centos7

one. wget https://dev.mysql.com/get/mysql57-commu...

Solution to forgetting mysql password under linux

The problem is as follows: I entered the command ...

js implementation of verification code case

This article example shares the specific code of ...

Let's talk about the storage engine in MySQL

Basics In a relational database, each data table ...

Linux editing start, stop and restart springboot jar package script example

Preface In the springboot configuration file, the...