CentOS下 MySQL同步备份
MySQL支持单向、异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器。主服务器将更新写入二进制日
注释:MySQL支持单向、异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器。主服务器将更新写入二进制日志文件,并维护日志文件的一个索引以跟踪日志循环。服务器在日志中读取的最后一次成功更新的位置。从服务器接收从那时起发生的任何更新,然后封锁并等待主服务器通知下一次更新。在实际项目中,,两台分布于异地的主机上安装有MySQL数据库,两台服务器互为主备,客户要求当其中一台机器出现故障时,另外一台能够接管服务器上的应用,这就需要两台数据库的数据要实时保持一致,在这里使用MySQL的同步功能实现双机的同步复制。
以下是操作实例:
一、环境配置
1、主数据服务端:CentOS release 5.6 mysql-5.0.77-4.el5_5.4 IP:192.168.4.200
2、从数据客户端:CentOS release 5.69 mysql-server-5.0.95-5.el5_9 IP:192.168.4.244
二、在主、从数据库增加同步账号
1、在主库增加一个从库可以登录的账号
MySQL>
GRANT all privileges ON *.* TO tongbu@'192.168.4.244' IDENTIFIED BY '123456';
(注意:tongbu是用于同步的帐号,123456是tongbu的密码)
2、在从库增加一个主库可以登录的账号
MySQL>
GRANT all privileges ON *.* TO tongbu@'192.168.4.200' IDENTIFIED BY '123456';
(注意:tongbu是用于同步的帐号,123456是tongbu的密码)
三、配置数据库参数
1、以root用户登录主库,修改主库my.cnf文件;
[root@jw01 mysql]# vim /etc/my.cnf
[mysqld]下面增加以下的参数;
default-character-set=utf8
log-bin=MySQL-bin
relay-log=relay-bin
relay-log-index=relay-bin-index
server-id=1
master-host=192.168.4.244 #同步服务器的IP
master-user=tongbu #用于同步的帐号
master-password=123456 #用于同步帐号的密码
master-port=3306 #同步服务器的端口
master-connect-retry=30 #同步的时间间隔,单位是秒
binlog-do-db=zhubao #需要同步的库,zhubao、HyDatabase、zentao、collect;
binlog-do-db=HyDatabase
binlog-do-db=zentao
binlog-do-db=collect
replicate-do-db=zhubao
replicate-do-db=HyDatabase
replicate-do-db=zentao
replicate-do-db=collect
2、以root用户登录从库,修改从库my.cnf文件;
[root@jw02 mysql]# vim /etc/my.cnf
[mysqld]下面增加以下的参数;
default-character-set=utf8
log-bin=MySQL-bin
relay-log=relay-bin
relay-log-index=relay-bin-index
server-id=2
master-host=192.168.4.200
master-user=tongbu
master-password=123456
master-port=3306
master-connect-retry=30
binlog-do-db=zhubao
binlog-do-db=HyDatabase
binlog-do-db=zentao
binlog-do-db=collect
replicate-do-db=zhubao
replicate-do-db=HyDatabase
replicate-do-db=zentao
replicate-do-db=collect
slave-net-timeout=60 #当slave从主数据库读取log数据失败
slave-skip-errors=all #忽略错误的参数

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySql is a commonly used relational database management system that is widely used in various business and application scenarios. For MySQL backup issues, the selection and execution method of the backup plan are crucial. In this article, we will introduce various backup options and how to create and restore MySQL backups efficiently. 1. Selection of backup plan In the process of selecting a MySQL backup plan, you should choose a backup plan that suits you based on the business scenario and actual situation. Cold backup The so-called cold backup is to complete the MySQL database.

How to use MySQL data backup and recovery tools to achieve disaster recovery. Data backup and recovery are a very important part of the database management process. Backing up your data protects your database from accidental corruption, hardware failure, or other catastrophic events. As a popular relational database management system, MySQL provides some powerful tools to achieve data backup and recovery. This article will introduce how to use MySQL's data backup and recovery tools to achieve disaster recovery. MySQL data backup tool-mysql

In the MySQL database, each InnoDB table corresponds to an .ibd file, which stores the table's data and indexes. Therefore, for the management and maintenance of MySQL database, the management of ibd files is also particularly important. This article will introduce how to effectively manage and maintain ibd files in a MySQL database and provide specific code examples. 1. Check and optimize table space First, we can check the disk space usage of the table using the following SQL statement: SELECTTAB

MySQL is a popular relational database that is widely used in various fields. However, like other applications, MySQL has risks such as data corruption, crashes, and malicious attacks. Therefore, backing up your data is crucial. Backups can provide security and some form of "undo" functionality to data, reducing or even eliminating instability and risk. The most common backup types are full backup and incremental backup. However, if you need frequent, real-time backups, rolling backups are a better approach. A rolling backup is when an acceptable

MySQL is one of the most widely used relational database management systems currently. Its efficiency and reliability make it the first choice for many enterprises and developers. But for various reasons, we need to back up the MySQL database. Backing up a MySQL database is not an easy task because once the backup fails, important data may be lost. Therefore, in order to ensure data integrity and recoverability, some measures must be taken to achieve efficient MySQL database backup and recovery. This article will introduce how to achieve

Analysis of MySQL database backup and recovery performance tuning project experience In daily operation and maintenance, MySQL database backup and recovery work is indispensable. However, in the face of multi-terabyte or even petabyte-level data scale, the time and resource consumption required for backup and recovery often become key factors restricting database performance. This article will share some practical experiences and techniques through a practical case of backup and recovery performance tuning for a large Internet enterprise. 1. Selection of backup solutions. Based on different business needs and data scale, the selection of backup solutions should also be considered.

MySQL is currently one of the most popular relational database management systems and is widely used in enterprise-level applications. Whether you are a developer or a data administrator, you need to understand the basic knowledge of MySQL backup and recovery. Backup and recovery not only help enterprises protect data, but also enable systems to respond quickly to adverse situations and restore them to normal operating conditions as much as possible. This article will detail the steps for MySQL backup and recovery and provide some best practices to help readers go further in protecting their MySQL databases.

There is no absolutely optimal MySQL database backup and recovery solution, and it needs to be selected based on the amount of data, business importance, RTO and RPO. 1. Logical backup (mysqldump) is simple and easy to use, suitable for small databases, but slow and huge files; 2. Physical backup (xtrabackup) is fast, suitable for large databases, but is more complicated to use. The backup strategy needs to consider the backup frequency (RPO decision), backup method (data quantity and time requirement decision) and storage location (off-site storage is more secure), and regularly test the backup and recovery process to avoid backup file corruption, permission problems, insufficient storage space, network interruption and untested issues, and ensure data security.
