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

Vue3.x uses mitt.js for component communication

Table of contents Quick Start How to use Core Pri...

Detailed explanation of Vue slot

1. Function : Allows the parent component to inse...

How to convert JavaScript array into tree structure

1. Demand The backend provides such data for the ...

Eclipse configures Tomcat and Tomcat has invalid port solution

Table of contents 1. Eclipse configures Tomcat 2....

Detailed explanation of the execution process of MySQL query statements

Table of contents 1. Communication method between...

In-depth analysis of the Tomcat server of Centos 7 system

Table of contents 1. The origin of tomcat 1. Tomc...

How to use the dig/nslookup command to view DNS resolution steps

dig - DNS lookup utility When a domain name acces...

Summary of the differences between Mysql primary key and unique key

What is a primary key? A primary key is a column ...

Vue3+script setup+ts+Vite+Volar project

Table of contents Create a vue + ts project using...

The pitfalls of deploying Angular projects in Nginx

Searching online for methods to deploy Angular pr...

Detailed discussion of InnoDB locks (record, gap, Next-Key lock)

Record lock locks a single index record. Record l...

MySQL uses the Partition function to implement horizontal partitioning strategy

Table of contents 1 Review 2 Five strategies for ...