这篇文章为自己动手后的操作记录,以下是我这次主从配置的过程,请大家多多指教:
环境:
1. 两台windows7笔记本。
2. 安装数据库版本,使用 select version();
看到主库上是:
mysql> select version();
+-------------------------+| version() |+-------------------------+| 5.0.45-community-nt-log |+-------------------------+1 row in set
同样,从库上是:
mysql> select version();
+---------------------+| version() |+---------------------+| 5.0.45-community-nt |+---------------------+1 row in set
配置步骤:
1. 修改主库机器上的my.ini文件:
末尾增加:
#主库的serverId 还不清楚怎么使用。但不能和从库相同
server-id=559#设置bin.log文件地址,但是我本地生成的不是log-bin.log而是log-bin.000001 ,log-bin.000002 等等文件log-bin = D:\log-bin.log#设置一个错误日志,和bin.log一样会在启动的时候更新log-error=D:\log-err.log
2. 在主库上增加从库的用户信息:
grant replication slave on *.* to 'slave_test'@'10.28.164.123' identified by 'slave_test';
3. 修复从库上的my.ini文件:
#从库的serverId
server-id=558#配置主库的ip地址master-host=10.28.162.35#从库连接主库的用户名master-user=slave_test#密码master-password=slave_test#尝试次数master-connect-retry=30#主库的库名replicate-do-db=master_db
配置好后,各自重启mysql服务:
主库上查看状态
mysql> show master status;
+----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------+----------+--------------+------------------+
| log-bin.000003 | 13484 | | |
+----------------+----------+--------------+------------------+
1 row in set
+----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------+----------+--------------+------------------+
| log-bin.000003 | 13484 | | |
+----------------+----------+--------------+------------------+
1 row in set
从库上查看状态:
+----------------------+--------------+--------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------+--------------+--------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Connecting to master | 10.28.162.35 | slave_test | 3306 | 30 | | 4 | slave-relay-bin.000003 | 98 | | No | Yes | cms | | | | | | 0 | | 0 | 0 | 98 | None | | 0 | No | | | | | | NULL |
+----------------------+--------------+--------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------+--------------+--------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Connecting to master | 10.28.162.35 | slave_test | 3306 | 30 | | 4 | slave-relay-bin.000003 | 98 | | No | Yes | cms | | | | | | 0 | | 0 | 0 | 98 | None | | 0 | No | | | | | | NULL |
+----------------------+--------------+--------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set
注意:
Slave_IO_Running | Slave_SQL_Running
No | Yes
正常情况这里应该是两个Yes,并且Master_Log_File 字段为空的(这里需要配置)
网上说的情况有两种:
1. 从库的用户没有权限。
2. 主库的binlog文件不存在。
我检查后发现没有这两种情况,于是 我重启slave 一次执行:
1. slave stop ;命令
2. change master to Master_Log_File='log-bin.000003',Master_Log_Pos=98; #将日志文件重新设置一次,对应于 show master status 看到的File字段。
3. slave start;
还是不行。于是我重新修改了master的日志文件:
mysql> change master to Master_Log_File='log-bin.000004',Master_Log_Pos=98;
Query OK, 0 rows affected
mysql> show master status;
+----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------+----------+--------------+------------------+
| log-bin.000004 | 8774 | | |
+----------------+----------+--------------+------------------+
1 row in set
mysql> show master status;
+----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------+----------+--------------+------------------+
| log-bin.000004 | 8774 | | |
+----------------+----------+--------------+------------------+
1 row in set
然后再修改从库的 Master_Log_File:
1. slave stop ;命令
2. change master to Master_Log_File='log-bin.000004',Master_Log_Pos=98; #将日志文件重新设置一次
3. slave start;
再看slave状态:
mysql> show slave status;
+----------------------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | 10.28.162.29 | root | 3306 | 30 | log-bin.000004 | 8774 | CDYJY-ZHANGSB-relay-bin.000002 | 8909 | log-bin.000004 | Yes | Yes | cms | | | | | | 0 | | 0 | 8774 | 8909 | None | | 0 | No | | | | | | 0 |
+----------------------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+--------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set
全部是Yes,状态正常了。
这个时候,主库插入数据,从库就可以正常同步啦~~~!
值得注意的几个问题:
可以看到 log-err.log后有这么一句话:
130801 15:12:02 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=D:\Program Files\Database\MySQL\Data\xxxx-relay-bin' to avoid this problem.
解释如下:
master(binlog)->relay log(slave io线程)->db data(salve sql线程)
所以这些日志就放到relay log
然后从服务器慢慢执行master的二进制日志 传递给从服务器执行
从服务器需要一个缓冲吧
其中relay log是放在主库本地的。
这次只是简单的配置了主从同步,对于Mysql的大部分日志文件的用处还不是非常理解。需要在深入学习下。
相关推荐
MySQL 主从同步配置过程 一、 MySQL 主从同步配置概述 MySQL 主从同步配置是指将 MySQL 数据库的数据从一台服务器(主服务器)同步到另一台服务器(从服务器)的过程。这种配置可以实现数据的高可用性和灾难恢复,...
Linux-Mysql 主从同步配置 本文将详细解释 Linux-Mysql 主从同步配置的步骤和知识点。 一、主服务器配置 1. 编辑数据库配置文件 my.cnf, 一般在/etc/目录下。 2. 在[mysqld]下面加入以下代码: * log-bin=mysql...
### Linux下MySQL主从同步配置详解 #### 一、引言 在数据库管理领域,MySQL主从同步是一种常见的数据复制技术,它可以帮助我们构建高可用性和数据冗余性,从而提高系统的稳定性和可靠性。本文将详细介绍如何在Linux...
MySQL主从同步配置和实现 MySQL主从同步是指将一个MySQL服务器的数据实时地复制到另一个或多个服务器上,以实现数据的高可用性和灾难恢复。这种方式可以实现数据的热备援、读写分离、负载均衡等功能。 1. 案例 1:...
从其他地方复制的,不是用来赚分的,存粹是自己备份在网上,请下载的人自己看清楚
详解Mysql主从同步配置实战.doc
总之,MySQL主从同步配置涉及多个步骤,包括服务器安装、权限配置、数据库创建、配置文件修改和数据传输。这种配置能够提高系统的可用性和性能,尤其是在高并发场景下,通过读写分离,可以将读操作分散到从服务器,...
在Windows操作系统下配置MySQL主从同步涉及多个步骤,以下将详细解读配置的原理、步骤、优缺点等内容。 MySQL主从同步原理: MySQL主从同步的核心在于主库(Master)记录更改操作的二进制日志(binlog),从库...
配置 MySQL 主从同步主要包括以下几个步骤: 1. **开启 Binary Log**: - Master 端需要启用二进制日志(Binary Log),因为它记录了所有改变数据库状态的事务。可以通过在 MySQL 启动时使用 `--log-bin` 参数,...
超详细MySQL主从配置和主主同步总结。。。。。。。。。
淘宝资深工程师丁奇在2009年的分享中详细介绍了MySQL主从同步的原理、配置、优化以及在实际应用中遇到的问题和解决方案。 首先,MySQL主从同步的基本概念指的是在一个数据库实例(主库)上对数据进行修改操作后,...
主从同步配置 在 Master 节点上,我们需要配置 binlog 机制,并指定需要同步的数据库和表。在 Slave 节点上,我们需要配置 Slave 的连接信息,并启动 Slave 服务。 ``` CHANGE MASTER TO MASTER_HOST='58.214.17....
dble配置mysql主从同步
### MySQL 主从库配置详解 #### 一、MySQL 安装与环境变量设置 在进行 MySQL 主从库配置之前,我们需要确保已经正确安装了 MySQL,并设置了相应的环境变量。以下是具体的步骤: 1. **下载 MySQL 免安装版**: - ...
在Windows环境下,MySQL主从同步备份是一种常见的高可用性和数据冗余策略,确保数据的安全性和一致性。以下是详细步骤,适用于MySQL 5.0版本: 1. **创建备份账户**: 在主服务器A上,我们需要创建一个用于复制的...
MySQL主从同步是一种常见的数据库高可用性和数据冗余策略,它...总之,MySQL主从同步涉及到多个步骤,包括环境配置、权限设置、数据同步和监控优化。正确配置和维护主从同步能够确保数据库系统的稳定性和数据安全性。
希望能帮助读者朋友们解决关于主从同步中的一些疑问。八怪写作风格很是严谨,几乎每篇都是从源码入手去剖析MySQL主从复制相关的知识点。 强烈推荐大家订阅本专栏 业界大咖推荐序 从2016年开始八怪(本名高鹏)经常...
MySQL主从半同步复制是介于异步复制和全同步复制之间的一种模式,它提供了更好的数据安全性和一致性,同时也尽可能地减少了性能损失。 首先,我们来了解一下什么是MySQL半同步复制。在半同步复制模式下,主服务器在...