数据库的同步一直是个很重要的问题,也是一个难题,所幸mysql提供了多种方法可以用来同步
在本文中我先给出mysql本身自带的方式master-slave方式,详尽的步骤如下:

1、prepare

### 需要修改主、从服务器的my.cnf文件 ###

1) master
mysql> grant replication client,replication slave on *.* to ‘repl’@'192.168.0.*’ identified by ‘xxxxxx’

=========================================================================
### 主服务器 ###
# Replication Master Server (default)
# binary logging is required for replication
log-bin=/mysql/bin-log
log-bin-index=/mysql/bin-log.index
#binlog_cache_size = 1M
binlog_do_db = test1
binlog_do_db = test2
#binlog_ignore_db =

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 2370
=========================================================================

2) slave
mysql> grant replication client,replication slave on *.* to ‘repl’@'192.168.0.*’ identified by ‘xxxxxx’

=========================================================================
### 从服务器 ###
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
server-id = 2379
#
# The replication master for this slave - required
master-host = 192.168.0.240
#
# The username the slave will use for authentication when connecting
# to the master - required
master-user = repl
#
# The password the slave will authenticate with when connecting to
# the master - required
master-password = xxxxxx
#
# The port the master is listening on.
# optional - defaults to 3306
master-port = 3306
#
# binary logging - not required for slaves, but recommended
#log-bin=/mysql/log/slavebin-log

master-info-file = /mysql/log/master.info
relay-log-info-file = /mysql/log/relay-log.info

replicate_do_db = test1
replicate_do_db = test2
#replicate_ignore_db = …
#replicate_do_table =
#replicate_ignore_table =
#replicate_wild_do_table =
#replicate_wild_ignore_table = …
#replicate_wild_ignore_table = temp\_subpost\_%
#replicate_rewrite_db=->
# 1062: dup key entry
# 1064: sql syntax
#slave_skip_errors = 1062,1064
slave_skip_errors = 1062
relay-log = /mysql/log/relay-log
relay-log-index = /mysql/log/relay-log.index
=========================================================================

### below step will start the work ###
=========================================================================
cd /opt/mysql/bin
ln -s /opt/mysql/share/mysql/mysql.server mysqlctl
=========================================================================

2、stop mysql
1) master: mysqlctl stop && ps auxww|grep mysql
2) slave: mysqlctl stop && ps auxww|grep mysql

3、start master’s mysql
mysqlctl start
ps auxww|grep mysql
mysql >flush tables;
mysql >show master status \G
mysql >reset master
mysqlctl stop

4、start slave’s mysql
mysqlctl start
ps auxww|grep mysql
mysql >stop slave
mysql >show slave status \G
mysql >reset slave;
mysqlctl stop

5、start master’s mysql
mysqlctl start
mysql >show master status \G
mysql >flush tables with read lock
mysql >show master status \G

## record the bin-log and positon ##

6、synchronization master’s datas to slave
rsync -avP “master’s datas” “slave’s datas directory”

7、start slave’s mysql
mysqlctl start –skip-slave-start
mysql >show slave status \G
mysql >change master to
-> MASTER_HOST=’master_host_name’,
-> MASTER_USER=’replication_user_name’,
-> MASTER_PASSWORD=’replication_password’,
-> MASTER_LOG_FILE=’recorded_log_file_name’,
-> MASTER_LOG_POS=recorded_log_position;

## Note:slave’s file and pos must be the same with with master’s ##

8、master
mysql >unlock tables;

9、slave
mysql >show slave status \G

## Note: Seconds_behind_master=0
## Slave_IO_Running=YES,Slave_SQL_Running=YES

10、checking the slave’s database updated real-time whether or not ??

转载于:https://blog.51cto.com/badboy6515/634960

mysql数据库同步 debug相关推荐

  1. MySQL数据库同步小工具(Java实现)

    近期公司做个报表系统,为了报表系统中复杂的查询条件,不影响线上业务系统的使用,研究了一下MySQL数据库同步,下面用Java代码实现MySQL数据库同步,以便自己查阅! 数据库同步实现功能点: 1.支 ...

  2. MySQL数据库同步神器 - Gravity - 比Datax好用

    MySQL数据库同步神器 - Gravity 原始地址:https://github.com/moiot/gravity 同步地址:  https://gitee.com/yunwisdoms/gra ...

  3. php mysql数据库同步_实现MySQL数据库同步实例演示_MySQL

    本次实验的主要目的是剖析配置MySQL(和PHP搭配之最佳组合) 数据库的主辅MySQL数据库同步的实际操作步骤,我前两天在相关网站看见的资料,觉得挺好,就拿出来供大家分享,开始具体的配置. 本次试验 ...

  4. mysql数据库同步时间_MySQL 数据库同步

    简明现代魔法 -> 数据库技术 -> MySQL 数据库同步 MySQL 数据库同步 2010-01-15 MySQL 的数据同步,在 MySQL 官方网站文档上,叫 Replicatio ...

  5. android与mysql数据库同步_android开发 如何通过web服务器访问MYSQL数据库并且使其数据同步到android SQLite数据库?...

    通过web服务器访问MYSQL数据库有以下几个过程: 1.在MySql下创建自己的数据库和自己的表单 2.连接数据库. 3.访问数据库 1.创建web工程 (服务器端) 在Myeclipse下新建一个 ...

  6. ubuntun系统mysql数据库同步_Ubutun 14.10下mysql 主从同步详细操作

    d)配置MySQL从服务器的my.cnf文件 vi /etc/my.cnf #编辑配置文件,在[mysqld]部分添加下面内容 server-id=2 #配置文件中已经有一行server-id=1,修 ...

  7. ubuntun系统mysql数据库同步_Canal 实现 Mysql数据库实时数据同步

    简介 1.1 canal介绍 ​ Canal是一个基于MySQL二进制日志的高性能数据同步系统.Canal广泛用于阿里巴巴集团(包括https://www.taobao.com),以提供可靠的低延迟增 ...

  8. MySQL可运行在不同的操作系统下_不同操作系统下的mysql数据库同步

    当数据库的数据量读写频繁的时候,我们就要考虑把数据库的读写分开,以提高数据库的使用效率,(当然还有其他用处比如,备份数据),这个时候我们就要用到mysql的一个功能,数据库同步.下面就具体讲一下实现方 ...

  9. linux同步数据库,Linux两台服务器mysql数据库同步

    我们在做web系统部署的时候往往涉及到两台甚至多台数据库的备份,为了数据安全考虑(虽然说到底不过是一堆0 1,但是价千金啊),所以我们还是乖乖做同步把! 1.准备两台Linux服务器(主.从) 2.安 ...

最新文章

  1. Python学习之字符串
  2. python从入门到精通视频教程百度云-let's python从入门到精通视频教程
  3. 【BZOJ3196】Tyvj 1730 二逼平衡树
  4. 查阅文献时向原作者发邮件要文献的简单模板
  5. 【数学基础】运筹学:拉格朗日乘子法和KKT条件(上)
  6. 5000字超干货|如何用数据分析驱动用户增长
  7. mysql linux 安装_mysql-5.7.28 在Linux下的安装教程图解
  8. JS中数组和字符串具有的方法,以及substring,substr和slice的用法与区别
  9. Android控件系列之XML静态资源
  10. 使用管道和rm命令遇到的问题
  11. 【ffmpeg】不带透明通道的视频overlay
  12. 网站开发流程以及HTML5简介(十)
  13. MDUI的黑暗模式实现和居中问题
  14. 给你一份完整的自动阅读所需介绍
  15. AI(人工智能)园区顶层设计方案(ppt)
  16. 快速添加百度网盘文件到Aria2 猴油脚本
  17. 分析方法论_用户生命周期的建立
  18. matlab对三维矩阵求和,【求助】多维矩阵求和运算!!
  19. android 自定义数字键盘
  20. 误操作导致系统进不去得重装,C盘资料没备份?!别慌,还有救!-200820

热门文章

  1. VS2017新建视图中文乱码解决办法
  2. H5新特性 input type=date 在手机上默认提示显示无效解决办法
  3. PAT天梯赛练习题——L3-005. 垃圾箱分布(暴力SPFA)
  4. 找区间连续值(HDU5247)
  5. 【转】你必须了解的Session的本质
  6. CentOS-6.4安装配置Nginx
  7. C primer plus -- Chapter 2
  8. 漫谈词向量之基于Softmax与Sampling的方法
  9. 神经网络架构演进史:全面回顾从LeNet5到ENet十余种架构
  10. [Rtsp]RTSP对实时摄像头视频流进行转换(FFmpeg+FFserver)