Home Database Mysql Tutorial MySQL主从复制不一致的解决办法

MySQL主从复制不一致的解决办法

Jun 07, 2016 pm 05:52 PM
master-slave replication

稍微有些规模的网站,基本上都会配置mysql主从复制,一方面用mysql的主从做数据库的读写分离,另一方面mysql本身的单机备份不是很强,一般采用主从架构,在从上进行数据备份。

在MySQL主从复制程中或多少出现一些主从不同步的情况,本文将对数据主从不同步的情况进行简单的总结,请注意本文主要从数据库层面上探讨数据库的主从不一致的情况。
1.网络的延迟

由于mysql主从复制是基于binlog的一种异步复制,通过网络传送binlog文件,理所当然网络延迟是主从不同步的绝大多数的原因,特别是跨机房的数据同步出现这种几率非常的大,所以做读写分离,注意从业务层进行前期设计。

2.主从两台机器的负载不一致

由于mysql主从复制是主数据库上面启动1个io线程,而从上面启动1个sql线程和1个io线程,当中任何一台机器的负载很高,忙不过来,导致其中的任何一个线程出现资源不足,都将出现主从不一致的情况。

3.max_allowed_packet设置不一致

主数据库上面设置的max_allowed_packet比从数据库大,当一个大的sql语句,能在主数据库上面执行完毕,从数据库上面设置过小,无法执行,导致的主从不一致。

4.key自增键开始的键值跟自增步长设置不一致引起的主从不一致。

5.mysql异常宕机情况下,如果未设置sync_binlog=1或者innodb_flush_log_at_trx_commit=1很有可能出现binlog或者relaylog文件出现损坏,导致主从不一致。

6.mysql本身的bug引起的主从不同步。

7.版本不一致,特别是高版本是主,低版本为从的情况下,主数据库上面支持的功能,从数据库上面不支持该功能。

以上就是常见的一些主从不同步的情况。或许还有其他的一些不同步的情况,请说出你所遇到的主从不一致的情况。

基于以上情况,先保证max_allowed_packet、自增键开始点和增长点设置一致,再者牺牲部分性能在主上面开启sync_binlog,对于采用innodb的库,推荐配置下面的内容

 代码如下 复制代码

1、innodb_flush_logs_at_trx_commit = 1
2、innodb-support_xa = 1 # Mysql 5.0 以上
3、innodb_safe_binlog      # Mysql 4.0

同时在从数据库上面推荐加入下面两个参数

1、skip_slave_start
2、read_only

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to implement master-slave replication of MySQL database in PHP How to implement master-slave replication of MySQL database in PHP May 17, 2023 am 08:18 AM

With the rapid development of the Internet, Web applications are increasingly integrating database operations. MySQL is a world-renowned relational database system that is widely used. In highly concurrent web applications, MySQL master-slave replication is an important way to improve database performance and availability. This article will introduce how to use PHP to implement master-slave replication of MySQL database. 1. What is MySQL master-slave replication? MySQL master-slave replication refers to copying data from one MySQL database server to another server.

Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing Sep 09, 2023 am 10:57 AM

Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing In recent years, with the rapid development of the Internet, the database has become one of the core data storage and processing engines for most web applications. In this scenario, high availability and load balancing have become important considerations in database architecture design. As one of the most popular open source relational databases, MySQL's cluster deployment solution has attracted much attention. This article will introduce how to implement a highly available database cluster through MySQL master-slave replication and load balancing.

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

Detailed explanation of the master-slave replication function of Redis Detailed explanation of the master-slave replication function of Redis May 11, 2023 am 10:00 AM

Redis is an open source memory-based key-value storage system that is commonly used in scenarios such as caching, queuing, and real-time data processing. In large-scale applications, in order to improve the availability and performance of Redis, it is often necessary to adopt a distributed architecture, in which master-slave replication is a commonly used mechanism. This article will introduce the master-slave replication function of Redis, including definition, principle, configuration and application scenarios. 1. Definition of Redis master-slave replication refers to automatically synchronizing the data of one Redis node (i.e. master node) to other nodes (i.e. slave node).

How to configure master-slave replication of MySQL database? How to configure master-slave replication of MySQL database? Jul 13, 2023 pm 10:05 PM

How to configure master-slave replication of MySQL database? Master-slave replication of MySQL database is a common data backup and high availability solution. By configuring master-slave replication, you can synchronize data from one MySQL server (master server) to another (slave server), thereby improving database availability and performance. The following describes how to configure master-slave replication in a MySQL database and provides corresponding code examples. Make sure the MySQL server is installed and started. First, make sure MySQL is installed on your system.

Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication Sep 11, 2023 pm 05:51 PM

Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication. With the rapid development of the Internet industry, the demand for data storage and processing is getting higher and higher. In response to high concurrent access and massive data storage, cluster mode has become a common solution. Load balancing and disaster recovery are important components of the cluster system, and MySQL master-slave replication is a widely used method. This article will delve into load balancing and disaster recovery in cluster mode, focusing on the principle of MySQL master-slave replication.

Master-slave replication and high availability architecture in MySQL Master-slave replication and high availability architecture in MySQL Sep 09, 2023 pm 12:03 PM

Master-slave replication and high-availability architecture in MySQL As Internet applications and data volumes continue to grow, the high availability and scalability of the database are becoming more and more important. As a widely used open source relational database, MySQL provides master-slave replication and high-availability architecture solutions. Master-slave replication refers to the process of using a MySQL database instance as the master database and replicating its data to one or more slave databases (slave). This replication method can achieve redundant backup of data and separation of reading and writing.

Achieving data redundancy and expansion: application cases of MySQL master-slave replication technology in cluster environments Achieving data redundancy and expansion: application cases of MySQL master-slave replication technology in cluster environments Sep 08, 2023 pm 04:36 PM

Realizing data redundancy and expansion: Application cases of MySQL master-slave replication technology in cluster environments Introduction: With the development of the Internet, the increasing amount of data and the increasing number of users, traditional stand-alone databases can no longer meet the requirements of high concurrency and high availability. need. In this context, distributed databases have become one of the popular solutions. As one of the most commonly used relational databases, MySQL's master-slave replication technology has also received widespread attention in distributed databases. This article will introduce MySQL master-slave replication technology in a cluster environment

See all articles