---
title: "mysql 主从同步出问题，重新修复从库"
author: "tiantianfei"
date: "2011-01-31T11:32:01Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2011-01-31T11:32:01Z"
id: 900099
url: "https://hihitiger.iteye.com/blog/900099"
---

mysql 主从同步出问题，重新修复从库

2010-05-18 02:05

**主库相关操作**

1.flush tables with read lock;    //主库上锁表

2.show master status;   //记录 master log file及file position  
比如：  
+--------------------------+----------------+-------------------+------------------------+  
| File                          | Position       | Binlog\_Do\_DB | Binlog\_Ignore\_DB |  
+--------------------------+----------------+--------------------+-----------------------+  
| xxxx-log.000031     | 199039244     | xxxx                   |                              |   
+--------------------------+----------------+--------------------+-----------------------+

3.$tar -cvf database.tar ./data   //备份数据文件

4.unlock tables;   //解锁主库表

**从库相关操作**

1.将主库数据库文件copy到从库中  
2.启动从库  
3.stop slave;  
4.reset slave;  
5.change master to master\_host='10.xx.xx.xxx,master\_user='xxxx',master\_password='xxxx',master\_port=xxxx,master\_log\_file='xxxx-log.000031',master\_log\_pos=199039244;   
5.start slave;  
验证方法一：  
//登陆从库  
slave status\\G;

Slave\_IO\_Running: Yes  
Slave\_SQL\_Running: Yes  
上面2项都为'Yes'，表示slave正常

验证方法二：  
//登陆主库  
show processlist;  
Has read all relay log; waiting for the slave I/O thread to update it   
表示正常