Table of Contents
主从同步
master端配置
slave端配置
半同步配置
检查配置
Home Database Mysql Tutorial mysql5.5主从同步配置(semi_sync)

mysql5.5主从同步配置(semi_sync)

Jun 07, 2016 pm 04:41 PM
SEMI sync Synchronize Configuration

好久不折腾mysql主从了,发现5.5交之前的版本,配置上有些变化,趁着夜深人静,重温一下,顺便简单记录一下配置过程。 主从同步 master端配置 修改 my.cnf 文件 12345678910 vim /etc/my.cnf[mysqld]server-id = 1log-bin = mysql-binbinlog_format = mixede

好久不折腾mysql主从了,发现5.5交之前的版本,配置上有些变化,趁着夜深人静,重温一下,顺便简单记录一下配置过程。

主从同步

master端配置

  1. 修改my.cnf文件
1
2
3
4
5
6
7
8
9
10
Copy after login
Copy after login
Copy after login
vim /etc/my.cnf
[mysqld]
server-id = 1
log-bin = mysql-bin
binlog_format = mixed
expire-logs-days = 7
binlog-do-db = luxtarget
binlog-ignore-db = mysql
replicate-do-db = luxtarget
replicate-ignore-db = mysql
Copy after login
Copy after login
  1. 新建授权复制用户

    1
    2
    
    Copy after login
    grant replication slave on *.* to 'slave'@'xxx.xxx.xxx.xxx' identified by 'slave';
    flush privileges;
    
    Copy after login
  2. 重启mysql

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    service mysqld restart
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
  3. 锁定数据库,将数据打包并拷贝至slave

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    flush tables with read lock;
    
    Copy after login
  4. 查看master上二进制日志情况,记录FilePosition

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    show master status;
    
    Copy after login
  5. 当数据打包拷贝完毕,解除锁定;

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    ublock tables;
    
    Copy after login

    当数据较大时,将数据打包备份比使用mysqldump导入时效率更高

slave端配置

  1. 修改my.cnf文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    Copy after login
    Copy after login
    Copy after login
    vim /etc/my.cnf
    [mysqld]
    server-id = 2
    log-bin = mysql-bin
    binlog_format = mixed
    expire-logs-days = 7
    binlog-do-db = luxtarget
    binlog-ignore-db = mysql
    replicate-do-db = luxtarget
    replicate-ignore-db = mysql
    
    Copy after login
  2. 重启mysql

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    service mysqld restart
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
  3. 将从master拷贝来的数据导入slave

  4. 连接master开始同步

    1
    2
    3
    4
    5
    
    Copy after login
    change master to master_host='xxx.xxx.xxx.xxx',master_user='slave',master_password='slave',master_log_file='master-bin.xxxxxx,master_log_pos=xxx;
    start slave;
    show slave status\G;
    
    Copy after login

    当Slave_IO_Running与Slave_SQL_Running的状态都为Running时即可。

半同步配置

master端配置

  1. 安装mysql半同步插件

    1
    2
    3
    
    Copy after login
    INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
    SET GLOBAL rpl_semi_sync_master_enabled = 1;
    SET GLOBAL rpl_semi_sync_master_timeout = 1000;
    
    Copy after login
  2. 修改my.cnf文件

    1
    2
    3
    4
    
    Copy after login
    Copy after login
    vim /etc/my.cnf
    [mysqld]
    rpl_semi_sync_master_enabled=1 #启用半同步
    rpl_semi_sync_master_timeout=1000 #超时时间为1s
    
    Copy after login
  3. 重启mysql

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    service mysqld restart
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login

slave端配置

  1. 安装mysql半同步插件

    1
    2
    3
    4
    
    Copy after login
    Copy after login
    INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
    SET GLOBAL rpl_semi_sync_slave_enabled = 1;
    STOP SLAVE IO_THREAD;
    START SLAVE IO_THREAD;
    
    Copy after login
  2. 修改my.cnf文件

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    rpl_semi_sync_slave_enabled=1  #启用半同步复制
    
    Copy after login
  3. 重启mysql

    1
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    Copy after login
    service mysqld restart
    
    Copy after login
    Copy after login
    Copy after login
    Copy after login

检查配置

  1. master

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    Copy after login
    SHOW GLOBAL STATUS LIKE 'rpl_semi%';
    +--------------------------------------------+-------+
    | Variable_name                              | Value |
    +--------------------------------------------+-------+
    | Rpl_semi_sync_master_clients               | 1     |
    | Rpl_semi_sync_master_net_avg_wait_time     | 0     |
    | Rpl_semi_sync_master_net_wait_time         | 0     |
    | Rpl_semi_sync_master_net_waits             | 0     |
    | Rpl_semi_sync_master_no_times              | 0     |
    | Rpl_semi_sync_master_no_tx                 | 0     |
    | Rpl_semi_sync_master_status                | ON    |
    | Rpl_semi_sync_master_timefunc_failures     | 0     |
    | Rpl_semi_sync_master_tx_avg_wait_time      | 0     |
    | Rpl_semi_sync_master_tx_wait_time          | 0     |
    | Rpl_semi_sync_master_tx_waits              | 0     |
    | Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
    | Rpl_semi_sync_master_wait_sessions         | 0     |
    | Rpl_semi_sync_master_yes_tx                | 0     |
    +--------------------------------------------+-------+
    14 rows in set (0.00 sec)
    
    Copy after login
  2. slave

    1
    2
    3
    4
    5
    6
    7
    
    Copy after login
    mysql> SHOW GLOBAL STATUS LIKE 'rpl_semi%';
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | Rpl_semi_sync_slave_status | ON    |
    +----------------------------+-------+
    1 row in set (0.01 sec)
    
    Copy after login

好久不折腾mysql主从了,发现5.5交之前的版本,配置上有些变化,趁着夜深人静,重温一下,顺便简单记录一下配置过程。

主从同步

master端配置

  1. 修改my.cnf文件
1
2
3
4
5
6
7
8
9
10
Copy after login
Copy after login
Copy after login
vim /etc/my.cnf
[mysqld]
server-id = 1
log-bin = mysql-bin
binlog_format = mixed
expire-logs-days = 7
binlog-do-db = luxtarget
binlog-ignore-db = mysql
replicate-do-db = luxtarget
replicate-ignore-db = mysql
Copy after login
Copy after login
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)

The working principle and configuration method of GDM in Linux system The working principle and configuration method of GDM in Linux system Mar 01, 2024 pm 06:36 PM

Title: The working principle and configuration method of GDM in Linux systems In Linux operating systems, GDM (GNOMEDisplayManager) is a common display manager used to control graphical user interface (GUI) login and user session management. This article will introduce the working principle and configuration method of GDM, as well as provide specific code examples. 1. Working principle of GDM GDM is the display manager in the GNOME desktop environment. It is responsible for starting the X server and providing the login interface. The user enters

One or more items in the folder you synced do not match Outlook error One or more items in the folder you synced do not match Outlook error Mar 18, 2024 am 09:46 AM

When you find that one or more items in your sync folder do not match the error message in Outlook, it may be because you updated or canceled meeting items. In this case, you will see an error message saying that your local version of the data conflicts with the remote copy. This situation usually happens in Outlook desktop application. One or more items in the folder you synced do not match. To resolve the conflict, open the projects and try the operation again. Fix One or more items in synced folders do not match Outlook error In Outlook desktop version, you may encounter issues when local calendar items conflict with the server copy. Fortunately, though, there are some simple ways to help

The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps Feb 21, 2024 pm 12:00 PM

PyCharm is a powerful integrated development environment (IDE), and PyTorch is a popular open source framework in the field of deep learning. In the field of machine learning and deep learning, using PyCharm and PyTorch for development can greatly improve development efficiency and code quality. This article will introduce in detail how to install and configure PyTorch in PyCharm, and attach specific code examples to help readers better utilize the powerful functions of these two. Step 1: Install PyCharm and Python

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

How to configure workgroup in win11 system How to configure workgroup in win11 system Feb 22, 2024 pm 09:50 PM

How to configure a workgroup in Win11 A workgroup is a way to connect multiple computers in a local area network, which allows files, printers, and other resources to be shared between computers. In Win11 system, configuring a workgroup is very simple, just follow the steps below. Step 1: Open the "Settings" application. First, click the "Start" button of the Win11 system, and then select the "Settings" application in the pop-up menu. You can also use the shortcut "Win+I" to open "Settings". Step 2: Select "System" In the Settings app, you will see multiple options. Please click the "System" option to enter the system settings page. Step 3: Select "About" In the "System" settings page, you will see multiple sub-options. Please click

How to configure and install FTPS in Linux system How to configure and install FTPS in Linux system Mar 20, 2024 pm 02:03 PM

Title: How to configure and install FTPS in Linux system, specific code examples are required. In Linux system, FTPS is a secure file transfer protocol. Compared with FTP, FTPS encrypts the transmitted data through TLS/SSL protocol, which improves Security of data transmission. In this article, we will introduce how to configure and install FTPS in a Linux system and provide specific code examples. Step 1: Install vsftpd Open the terminal and enter the following command to install vsftpd: sudo

How to install and configure DRBD on CentOS7 system? Tutorial on implementing high availability and data redundancy! How to install and configure DRBD on CentOS7 system? Tutorial on implementing high availability and data redundancy! Feb 22, 2024 pm 02:13 PM

DRBD (DistributedReplicatedBlockDevice) is an open source solution for achieving data redundancy and high availability. Here is the tutorial to install and configure DRBD on CentOS7 system: Install DRBD: Open a terminal and log in to the CentOS7 system as administrator. Run the following command to install the DRBD package: sudoyuminstalldrbd Configure DRBD: Edit the DRBD configuration file (usually located in the /etc/drbd.d directory) to configure the settings for DRBD resources. For example, you can define the IP addresses, ports, and devices of the primary node and backup node. Make sure there is a network connection between the primary node and the backup node.

MyBatis Generator configuration parameter interpretation and best practices MyBatis Generator configuration parameter interpretation and best practices Feb 23, 2024 am 09:51 AM

MyBatisGenerator is a code generation tool officially provided by MyBatis, which can help developers quickly generate JavaBeans, Mapper interfaces and XML mapping files that conform to the database table structure. In the process of using MyBatisGenerator for code generation, the setting of configuration parameters is crucial. This article will start from the perspective of configuration parameters and deeply explore the functions of MyBatisGenerator.

See all articles