windows环境下mysql数据库的主从同步备份步骤(单向同步)
本文主要是向大家描述的是在windows环境之下实现MySQL数据库的主从同步备份的正确操作方案,以下就是文章的详细内容描述
以下的文章主要讲述的是在windows环境下实现MySQL数据库的主从同步备份的正确操作方案,我在一些相关的网站看见关于windows环境下实现MySQL数据库的主从同步备份的操作步骤描述,但是很少有对其成功操作到底的,所以拿出此篇较为完整的方案与大家一起分享。
以下配置在本机上已经成功:
实现功能:A为主服务器,B为从服务器,初始状态时,A和B中的数据信息相同,当A中的数据发生变化时,B也跟着发生相应的变化,使得A和B的数据信息同步,达到备份的目的。
环境:
A、B的MySQL数据库版本同为4.1.20
A:
操作系统:Windows 2003 server
IP地址:192.168.100.1
B:
操作系统:Windows 2003 server
的IP地址:192.168.100.2
配置过程:
1、在A的MySQL数据库中建立一个备份帐户,命令如下:
代码如下:
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.*
TO backup@'192.168.100.2'
IDENTIFIED BY '1234';
建立一个帐户backup,并且只能允许从192.168.100.2这个地址上来登陆,密码是1234。
2、因为mysql版本新密码算法不同,所以进入mysql下,输入:set password for 'backup'@'192.168.100.2'=old_password('1234');
3、关停A服务器,将A中的数据拷贝到B服务器中,使得A和B中的数据同步,并且确保在全部设置操作结束前,禁止在A和B服务器中进行写操作,使得两数据库中的数据一定要相同!
4、对A服务器的配置进行修改,打开mysql/my.ini文件,在[mysqld]下面添加如下内容:
server-id=10
log-bin=c:\log-bin.log
server-id:为主服务器A的ID值
log-bin:二进制变更日值
5、重启A服务器,从现在起,它将把客户堆有关数据库的修改记载到二进制变更日志里去。
6、关停B服务器,对B服务器锦熙配置,以便让它知道自己的镜像ID、到哪里去找主服务器以及如何去连接服务器。最简单的情况是主、从服务器分别运行在不同的主机上并都使用着默认的TCP/IP端口,只要在从服务器启动时去读取的mysql/my.ini文件里添加以下几行指令就行了。
代码如下:
[mysqld]
server-id=11
master-host=192.168.100.1
master-user=backup
master-password=1234
//以下内容为可选
replicate-do-db=backup
server-id:从服务器B的ID值。注意不能和主服务器的ID值相同。
master-host:主服务器的IP地址。
master-user:从服务器连接主服务器的帐号。
master-password:从服务器连接主服务器的帐号密码。
replicate-do-db:告诉主服务器只对指定的数据库进行同步镜像。
7、重启从服务器B。至此所有设置全部完成。更新A中的数据,B中也会立刻进行同步更新。如果从服务器没有进行同步更新,你可以通过查看从服务器中的mysql_error.log日志文件进行排错。
8、由于设置了slave的配置信息,mysql在数据库data目录下生成master.info,所以如有要修改相关slave的配置要先删除该文件,否则修改的配置不能生效。
binlog-do-db
官方文档推荐的是,在master端不指定binlog-do-db,在slave端用replication-do-db来过滤。
告诉主服务器,如果当前的数据库(即USE选定的数据库)是db_name,应将更新记录到二进制日志中。其它所有没有明显指定的数据库 被忽略。如果使用该选项,你应确保只对当前的数据库进行 ...
例如你设置了
代码如下:
binlog-do-db=db1
然后你执行了以下语句
use db1;
create database db2;
第二句语句并不会记入log
即使当前数据库是db1,因为考虑的是语句中的数据库名;
相反,除了CREATE DATABASE, ALTER DATABASE, and DROP DATABASE 以外的语句是对当前数据库有关的。
例如你设置了
代码如下:
binlog-do-db=db1
然后你执行了以下语句
use db2;
insert into db1.table1 values(1);
这条语句是不会计入log的,因为当前db是db2。而与操作db无关。
先在服务器端查询
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| updatelog.000012 | 15016 | data | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
由此可见两者的File、Position存在问题,所要要去Slave上设置对应主库的Master_Log_File、Read_Master_Log_Pos;执行如下语句;
mysql>slave stop;
mysql>CHANGE MASTER TO MASTER_HOST='192.168.0.1',MASTER_USER='test', MASTER_PASSWORD='******',MASTER_LOG_FILE='updatelog.000012',MASTER_LOG_POS=15016;
确保 Slave_IO_Running: Yes 、Slave_SQL_Running: Yes都要为YES才能证明Slave的I/O和SQL进行正常。
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=6267;
CHANGE MASTER TO
MASTER_HOST='192.168.1.100',
MASTER_USER='jb51',
MASTER_PASSWORD='www.jb51.net',
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=76146;
然后 在slave端查看 如果正常就oK了,都是yes
代码如下:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[ERROR] The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
查看 server_id; 一般情况下不建议大家用 1或2,建议用10,11防止出现
show variables like 'server_id';

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

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

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











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
