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

Quickly master the use of Docker to build a development environment

As the platform continues to grow, the project...

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that i...

Introducing multiple custom fonts in CSS3

Today I found a problem in HTML. There are many d...

Implementation of nginx worker process loop

After the worker process is started, it will firs...

Detailed explanation of the mysql database LIKE operator in python

The LIKE operator is used in the WHERE clause to ...

How to change $ to # in Linux

In this system, the # sign represents the root us...

Vue Element front-end application development: Use of API Store View in Vuex

Table of contents Overview 1. Separation of front...

How to uninstall MySQL cleanly (tested and effective)

How to uninstall Mysql perfectly? Follow the step...

mysql 5.6.23 winx64.zip installation detailed tutorial

For detailed documentation on installing the comp...

mysql replace part of the field content and mysql replace function replace()

[mysql] replace usage (replace part of the conten...

Detailed tutorial for installing MySQL on Linux

MySQL downloads for all platforms are available a...

Vue mobile terminal realizes finger sliding effect

This article example shares the specific code for...

An article to understand the use of proxies in JavaScript

Table of contents What is an agent Basic knowledg...

Analyze how a SQL query statement is executed in MySQL

Table of contents 1. Overview of MySQL Logical Ar...

Linux Cron scheduled execution of PHP code with parameters

1. Still use PHP script to execute. Command line ...