Table of Contents
introduction
Review of basic knowledge
Core concept or function analysis
Statement-Based Replication (SBR)
Row-Based Replication (RBR)
Mixed-Based Replication (MBR)
Example of usage
Basic usage of SBR
Advanced usage of RBR
Common Errors and Debugging Tips
Performance optimization and best practices
Home Database Mysql Tutorial Explain the difference between Statement-Based Replication (SBR), Row-Based Replication (RBR), and Mixed-Based Replication (MBR).

Explain the difference between Statement-Based Replication (SBR), Row-Based Replication (RBR), and Mixed-Based Replication (MBR).

Apr 08, 2025 am 12:04 AM
mysql copy Database replication

There are three main ways of replication in MySQL: SBR, RBR and MBR. 1. SBR records SQL statements, which are suitable for standard operations, but may cause data inconsistency. 2. RBR records data changes to ensure consistency, but the log is large. 3.MBR combines the two and selects the method according to the SQL type, which is flexible but complex. Consistency, performance, and complexity are considered when choosing.

Explain the difference between Statement-Based Replication (SBR), Row-Based Replication (RBR), and Mixed-Based Replication (MBR).

introduction

In the field of database replication, choosing the right replication method is crucial, which directly affects data consistency, performance, and system maintainability. Today we will explore three main MySQL replication methods: Statement-Based Replication (SBR), Row-Based Replication (RBR), and Mixed-Based Replication (MBR). Through this article, you will learn about the principles, advantages and disadvantages of each method, and the choice strategy in practical applications.

Review of basic knowledge

Before we get started, let's quickly review some of the basic concepts of MySQL replication. MySQL replication is a technology that replicates data from one MySQL database server (master server) to another or more MySQL database servers (slave servers). Replication can be used in various scenarios such as data backup, load balancing, and failover.

Core concept or function analysis

Statement-Based Replication (SBR)

The working principle of SBR is to record SQL statements executed on the master server into binary logs, then read these logs from the server and execute the same SQL statements to achieve data synchronization.

 -- SQL statement on the main server INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
Copy after login

The advantage of SBR is that the log file is smaller, because only the SQL statement itself is recorded. However, there are some challenges in SBR, such as some functions (such as NOW()) may produce different results on the master and slave server, resulting in inconsistent data.

Row-Based Replication (RBR)

RBR is different, it records changes in each row of data, not the SQL statement itself. This means that the slave server will accurately copy changes in data on the master server.

 -- Data changes on the main server INSERT INTO users VALUES (1, 'John Doe', 'john@example.com');
Copy after login

The advantage of RBR is that it can ensure data consistency because it records actual data changes, not SQL statements. However, RBR's log files are usually larger than SBR's because it requires recording changes in each line.

Mixed-Based Replication (MBR)

MBR combines the advantages of SBR and RBR, and it automatically chooses to use SBR or RBR according to the type of SQL statement. For example, for unsafe SQL statements (statements that may cause data inconsistencies), MBR will choose RBR.

 -- Select the copy method according to the type of SQL statement IF unsafe_statement THEN
    USE RBR;
ELSE
    USE SBR;
END IF;
Copy after login

The flexibility of MBR makes it the best choice in some scenarios, but also adds to the complexity of configuration and maintenance.

Example of usage

Basic usage of SBR

SBR is suitable for most standard SQL operations such as INSERT, UPDATE, and DELETE.

 -- Execute UPDATE products on the main server SET price = price * 1.1 WHERE category = 'Electronics';
Copy after login

The slave server will execute the same SQL statement to ensure the consistency of the data.

Advanced usage of RBR

RBR performs well when dealing with complex triggers and stored procedures because it accurately records changes on each row.

 -- Execute CREATE TRIGGER update_inventory AFTER INSERT ON orders on the primary server
FOR EACH ROW
BEGIN
    UPDATE inventory SET quantity = quantity - NEW.quantity WHERE product_id = NEW.product_id;
END;
Copy after login

RBR will record each row of data changes after the trigger is executed to ensure that the data on the slave server is consistent with the master server.

Common Errors and Debugging Tips

  • Inconsistent data in SBR : If nondeterministic functions (such as RAND()) are used, it may cause inconsistent data on the master and slave server. The solution is to avoid using these functions as much as possible, or switch to RBR.
  • Log files in RBR are too large : RBR's log files may become very large, affecting performance. The log size can be optimized by adjusting the binlog_row_image parameter.

Performance optimization and best practices

When choosing a copy method, the following factors need to be considered:

  • Data consistency : If data consistency is the primary consideration, RBR may be more suitable because it accurately records changes in each row.
  • Performance : SBR usually performs better in log size and performance, especially when dealing with a lot of simple SQL operations.
  • Complexity : MBR provides flexibility, but also increases configuration and maintenance complexity.

In practical applications, the appropriate copying method can be selected according to specific needs. For example, for an e-commerce platform, RBR may be more suitable because it ensures consistency in order data; while for a blog system, SBR may be more suitable because it provides better performance.

In short, choosing a suitable MySQL replication method requires comprehensive consideration of various factors such as data consistency, performance and system complexity. I hope this article can provide you with some valuable reference when choosing a copy method.

The above is the detailed content of Explain the difference between Statement-Based Replication (SBR), Row-Based Replication (RBR), and Mixed-Based Replication (MBR).. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Comparison of database replication and synchronization mechanisms between MySQL and TiDB Comparison of database replication and synchronization mechanisms between MySQL and TiDB Jul 14, 2023 am 09:07 AM

Comparison of database replication and synchronization mechanisms between MySQL and TiDB With the advent of the big data era, the amount of data continues to grow, and traditional database replication and synchronization mechanisms are inadequate in the face of high concurrency and large data volumes. In order to solve this problem, a new database system-TiDB has emerged, which is based on a distributed database architecture and can meet the storage and processing needs of massive data. This article will compare the database replication and synchronization mechanisms of MySQL and TiDB to discuss their advantages and disadvantages. 1. MySQL

Mirroring techniques for setting up data replication in MySQL Mirroring techniques for setting up data replication in MySQL Jun 15, 2023 am 11:03 AM

MySQL is a very popular relational database management system with good performance and stability. It is a database software widely used by many enterprises and organizations. In MySQL, data replication is a very important feature, which allows data to be synchronized between multiple database servers to ensure data security and reliability. Mirroring techniques for setting up MySQL data replication is the topic of this article. The basic concept of MySQL data replication. In MySQL, data replication refers to copying data in a MySQL instance.

Data master-slave replication technology in MySQL Data master-slave replication technology in MySQL Jun 14, 2023 pm 02:10 PM

MySQL database is a very popular relational database management system that supports a variety of data replication technologies, among which the more commonly used is master-slave replication technology. This article will introduce the data master-slave replication technology in MySQL, including principles, implementation methods, common problems and countermeasures. 1. Principle of master-slave replication technology The master-slave replication technology in MySQL can copy the data of a MySQL database to other servers to achieve data backup, load balancing, read-write separation and other functions. Its basic principle is to convert the main database

Explain MySQL semi-synchronous replication. Explain MySQL semi-synchronous replication. Apr 02, 2025 pm 07:21 PM

MySQL semi-synchronous replication balances data consistency and performance by waiting for at least one slave library to confirm before the master library returns to the client. 1) Enable semi-synchronous replication on the main library: SETGLOBALrpl_semi_sync_master_enabled=1;2) Enable semi-synchronous replication on the slave library: SETGLOBALrpl_semi_sync_slave_enabled=1; This method not only improves data consistency, but does not seriously affect performance like synchronous replication.

How to set up highly available database replication on Linux How to set up highly available database replication on Linux Jul 06, 2023 am 09:42 AM

How to set up highly available database replication on Linux Summary: In modern Internet applications, high availability of databases is very important, especially for key business scenarios such as online transactions and real-time data analysis. Database replication is a common way to achieve database high availability. This article will introduce how to set up highly available database replication on the Linux operating system to improve system availability and fault tolerance. Make sure the database server is configured correctly. Before you start setting up database replication, first make sure the database server is configured correctly.

MySql replication and clustering: how to implement large-scale distributed databases MySql replication and clustering: how to implement large-scale distributed databases Jun 16, 2023 am 08:04 AM

With the development of business and the gradual increase of data volume, a single database can no longer fully meet the needs, and distributed database systems have become an important solution in the industry. MySQL is currently one of the most popular relational databases, and there are many solutions for using MySQL to build distributed databases. In this article, we will delve into MySQL replication and clustering and how to implement large-scale distributed databases. 1. MySQL’s infrastructure MySQL’s infrastructure mainly consists of three parts: Client

MySQL and Oracle: Comparison of database replication and synchronization functions MySQL and Oracle: Comparison of database replication and synchronization functions Jul 13, 2023 pm 02:43 PM

MySQL and Oracle: Comparison of database replication and synchronization functions [Introduction] In today's information age, data, as one of the important resources of enterprises and organizations, has attracted more and more attention. The replication and synchronization functions of the database are widely used in data backup, load balancing, disaster recovery, and synchronization of multiple data centers. As two mainstream relational database management systems, MySQL and Oracle have their own advantages and characteristics in database replication and synchronization. This article will focus on MySQL and Oracle

PHP and PDO: How to perform database table copying and migration PHP and PDO: How to perform database table copying and migration Jul 29, 2023 am 08:13 AM

PHP and PDO: How to perform database table copying and migration When developing and maintaining applications, sometimes we need to perform database table copying and migration between different database environments. This may be because we need to deploy the application on a different server, or because we are upgrading or migrating the database. Whatever the case, using PHP and PDO (PHPDataObjects) is a convenient and flexible way to accomplish this task. First, let’s understand what PD is

See all articles