MySQL dual-machine hot standby implementation solution [testable]

MySQL dual-machine hot standby implementation solution [testable]

1. Concept

1. The difference between hot backup and backup

Hot backup refers to: High Available (HA), while backup refers to Backup, a type of data backup. These are two different concepts, and the products they correspond to are also two completely different products in terms of functions. Hot backup mainly ensures business continuity, and the method of implementation is to transfer the failure point. The main purpose of backup is to prevent data loss by making a copy, so backup emphasizes data recovery rather than application failover.

2. What is hot standby?

In a broad sense, hot standby means using two servers to back up each other and jointly perform the same service for important services. When a server fails, another server can take over the service task, thus automatically ensuring that the system can continue to provide services without the need for human intervention.

In a narrow sense, hot standby is the use of two servers that back up each other to jointly perform the same service, one of which is the working server (Primary Server) and the other is the backup server (Standby Server). When the system is normal, the working machine provides services for the application system, and the backup machine monitors the operation of the working machine (usually through heartbeat diagnosis, and the working machine also detects whether the backup machine is normal). When the working machine becomes abnormal and cannot support the operation of the application system, the backup machine actively takes over the work of the working machine and continues to support key application services to ensure uninterrupted operation of the system. Hot standby is a high-availability solution for failures in IT core servers, storage, and network routing switches.

2. Environmental Description

1. master

System: Windows 7

Database: mysql5.5

ip:192.168.0.123

2. Slave

System: Windows 7

Database: mysql5.5

ip:192.168.0.105

(Note: The version of the master server cannot be higher than that of the slave server, and the two servers must be in the same LAN)

3. Master-slave hot standby implementation

1. Account preparation

① On the master server, create a connection account for the slave server. The account must be granted REPLICATION SLAVE permissions. Enter the MySQL operation interface and enter the following SQL:

grant replication slave on *.* to 'replicate'@'192.168.0.105' identified by '123456';
flush privileges;

The operation is as shown in the figure:

②Verify the connection account

Use the replicat account on the slave server to access the master server database to see if the connection is successful.

Open a command prompt from the server and enter the following command:

mysql -h192.168.0.123 -ureplicate -p123456

If the following result appears, it means that the login is successful, which means that the two servers can be operated in dual-machine hot standby.

2. Master configuration

①Modify the mysql configuration file. After finding the my.ini configuration file and opening it, modify it under [mysqld]:

[mysqld]

server-id = 123 #Master ID, cannot be the same as slave ID

log-bin=mysql-bin#Set the generated log file name

binlog-do-db = test_db #Set the synchronization database name

replicate-do-db=test_db # Synchronize database name from server

binlog-ignore-db = mysql#Avoid syncing mysql user configuration

②Restart mysql service

Open the command prompt and enter the following two commands to complete the restart:

net stop mysql
net start mysql

③ Check the master server status

show master status;

④ Lock table

The purpose is to prevent new data from entering the environment so that the slave server can locate the synchronization position. After the initial synchronization is completed, remember to unlock

flush tables with read lock;

Steps ③④ are as shown below:

3. Slave configuration

①Modify the my.ini configuration file

log-bin=mysql-bin #Set the generated log file name
server-id=105# Slave ID, cannot be the same as the master ID
binlog-do-db=test_db #Set the synchronization database name
binlog-ignore-db=mysql #Avoid syncing mysql user configuration
replicate-do-db=test_db# Synchronize database name from server
replicate-ignore-db = mysql,information_schema,performance_schema

②Restart mysql service

③Use the change master statement to specify the synchronization position

After entering the MySQL operation interface, enter the following command:

stop slave;
reset slave;
change master to master_host='192.168.0.123',master_user='replicate',master_password='123456',master_log_file='mysql-bin.000124',master_log_pos=107;
start slave;

Note: The master_log_file and master_log_pos here must be consistent with the previous show master status query results

The operation is as shown in the figure:

4. Unlock the master table

unlock tables;

At this point, the master-slave hot standby is complete and can be tested.

Summarize

The above is the MySQL dual-machine hot standby implementation solution introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Two ways to manually implement MySQL dual-machine hot standby on Alibaba Cloud Server
  • Analysis of Difficulties in Hot Standby of MySQL Database
  • Configuration method of Mysql database dual-machine hot standby
  • Implementation steps of mysql dual-machine hot backup

<<:  How to use Linux tr command

>>:  Implementing a simple timer based on Vue method

Recommend

Ten Experiences in Web Design in 2008

<br />The Internet is constantly changing, a...

Swiper.js plugin makes it super easy to implement carousel images

Swiper is a sliding special effects plug-in built...

Let's talk about parameters in MySQL

Preface: In some previous articles, we often see ...

Use of Linux ls command

1. Introduction The ls command is used to display...

An example of implementing a simple finger click animation with CSS3 Animation

This article mainly introduces an example of impl...

Summary of the use of special operators in MySql

Preface There are 4 types of operators in MySQL, ...

Vue simple implementation of turntable lottery

This article shares the specific code of Vue to s...

Detailed analysis of SQL execution steps

Detailed analysis of SQL execution steps Let'...

Solution to the failure of docker windows10 shared directory mounting

cause When executing the docker script, an error ...

How MySQL supports billions of traffic

Table of contents 1 Master-slave read-write separ...

Vue+ElementUI implements paging function-mysql data

Table of contents 1. Problem 2. Solution 2.1 Pagi...

Detailed explanation of using Vue custom tree control

This article shares with you how to use the Vue c...

Analysis of Alibaba Cloud CentOS7 server nginx configuration and FAQs

Preface: This article refers to jackyzm's blo...