This article brings you an introduction to the MySQL two-way backup method (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
MySQL two-way backup is also called master-master backup, that is, both MySQL services are Master, and any one of them is the Slave of another service.
Preparation
Server
MySQL Server | Version | IP Address |
---|---|---|
masterA | 5.6.41 | 192.168.1.201 |
5.6.41 | 192.168.1.202 |
The backup MySQL server version should be kept consistent as much as possible. Different versions may have binary log formats. Not compatible.
Specific operation
AttentionDuring the operation, pay attention to the consistency of the data on both sides! ! ! masterA configurationmy.cnf[mysqld] # 服务器唯一标识 server-id=1 # 二进制日志文件名 log-bin=mysql-bin # 需要备份的数据库,多个数据库用 , 分隔 binlog-do-db=piumnl # 需要复制的数据库,多个数据库用 , 分隔 replicate-do-db=piumnl # 中继日志文件名 relay_log=mysqld-relay-bin # 手动启动同步服务,避免突然宕机导致的数据日志不同步 skip-slave-start=ON # 互为主从需要加入这一行 log-slave-updates=ON # 禁用符号链接,防止安全风险,可不加 symbolic-links=0 # 可不加 # resolve - [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0 master-info-repository=table relay-log-info-repository=table relay-log-recovery=1 # 可不加 # 禁用 dns 解析,会使授权时使用的域名无效 skip-host-cache skip-name-resolve sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESmasterB configurationmy.cnf
# 不再解释各个配置项 [mysqld] server-id=2 log-bin=mysql-bin binlog-do-db=piumnl replicate-do-db=piumnl relay_log=mysql-relay-bin skip-slave-start=ON log-slave-updates=ON symbolic-links=0 # resolve - [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0 master-info-repository=table relay-log-info-repository=table relay-log-recovery=1 skip-host-cache skip-name-resolve sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESCreate backup usermasterA & masterB both need to create a backup user:
create user 'rep'@'%' identified by 'rep'; # 创建一个账户 grant replication slave on *.* to 'rep'@'%'; # 授予该账户对任意数据库任意表的主从备份权限Note:
- MySQL under Linux is closed for the
- root@%
user
grant_privPermissions, so if it is a remote login, authorization failure will occur
The backup user account and password here may not be consistent, here to simplify the operation, use the same account and password
show master status\G; # 此处需要关注 File 和 Position 值Enable backup
stop slave; # master_log_file 就是第一步操作的 File 值 # master_log_pos 就是第一步操作的 Position 值 change master to master_host=<master_hostname>, master_user=<rep_username>, master_port=<master_port>, master_password=<rep_password>, master_log_file='mysql-log.000003', master_log_pos=154; start slave;</rep_password></master_port></rep_username></master_hostname>View the results
show slave status\G; # 查看最重要的两项,两个都必须为 Yes ,有一个为 No 都要去查看错误日志文件,看看什么地方存在问题 # Slave_IO_Running: Yes # Slave_SQL_Running: YesmasterB
Reverse the operation of masterA
TestInsert data into masterA and masterB respectively, and check whether the expected data appears on the other server in time ProblemMySQL Slave Failed to Open the Relay LogThis should be a problem with the relay log. You can try the following operationsstop slave; flush logs; start slave;Got fatal error 1236 from master when reading data from binary logWhen pulling the log from the main library, it is found that the first file in the mysql_bin.index file of the main library does not exist.
# 进行如下操作重置 # 如果二进制日志或中继日志有其他作用,请勿进行如下操作 reset master; reset slave; flush logs;
The above is the detailed content of Introduction to MySQL two-way backup method (with code). For more information, please follow other related articles on the PHP Chinese website!

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

在mysql中,是否需要commit取决于存储引擎:1、若是不支持事务的存储引擎,如myisam,则不需要使用commit;2、若是支持事务的存储引擎,如innodb,则需要知道事务是否自动提交,因此需要使用commit。

“mysql-connector”是mysql官方提供的驱动器,可以用于连接使用mysql;可利用“pip install mysql-connector”命令进行安装,利用“import mysql.connector”测试是否安装成功。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor
