准备:主备库版本一致,正常安装软件。

1、主库上设置一个复制使用的账户:

mysql> grant replication slave on *.* to 'rep1'@'192.168.100.136' identified by 'dbking';

Query OK, 0 rows affected (0.18 sec)

mysql> select user,host,password from mysql.user where user='rep1';

+------+-----------------+-------------------------------------------+

| user | host            | password                                  |

+------+-----------------+-------------------------------------------+

| rep1 | 192.168.100.136 | *0E5B9DDCEF035D1E653099F4143C0F36061F7653 |

+------+-----------------+-------------------------------------------+

1 row in set (0.08 sec)

2、修改主库参数文件,开启binlog并设置slave id:

log_bin=/usr/local/mysql/data/dbking-bin.log

server_id=1

3、主数据库上设置读锁定有效:

mysql> flush tables with read lock;

Query OK, 0 rows affected (0.00 sec)

4、然后得到主数据库上当前二进制日志文件及偏移量,为了在从库复制起点:

mysql> show master status;

+-------------------+----------+--------------+------------------+-------------------+

| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+-------------------+----------+--------------+------------------+-------------------+

| dbking-bin.000001 |      120 |              |                  |                   |

+-------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

5、主数据库目前已停止更新操作,现在要得到主数据库备份到从库上恢复:

[root@chavinking mysql]# tar -cvf data.dir data

6、解锁主库:

mysql> unlock tables;

Query OK, 0 rows affected (0.00 sec)

7、将主库备份恢复到从库:

[root@chavinking mysql]# mv data data1204

[root@chavinking mysql]# tar -xvf data.dir

8、修改从库my.cnf文件,设置server_id参数,server_id参数必须唯一:

server_id=2

9、从库使用--skip-slave-start启动数据库:

[root@chavinking mysql]# bin/mysqld_safe --skip-slave-start &

[1] 18389

[root@chavinking mysql]# 161202 08:50:16 mysqld_safe Logging to '/usr/local/mysql/data/chavinking.err'.

161202 08:50:16 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

10、对从库数据库服务器进行相应设置,制定复制使用账户,主库ip,端口以及开始进行复制的日志文件和位置等,具体如下:

本次试验脚本如下:

mysql> change master to

-> master_host='192.168.80.133',

-> master_user='rep1',

-> master_password='dbking',

-> master_port=3306,

-> master_log_file='dbking-bin.000001',

-> master_log_pos=120;

Query OK, 0 rows affected, 2 warnings (0.11 sec)

11、从库启动slave线程:

mysql> start slave;

Query OK, 0 rows affected (0.11 sec)

12、从库上查看配置信息:

mysql> show slave status \G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.80.133

Master_User: rep1

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: dbking-bin.000004

Read_Master_Log_Pos: 120

Relay_Log_File: chavinking-relay-bin.000008

Relay_Log_Pos: 284

Relay_Master_Log_File: dbking-bin.000004

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 120

Relay_Log_Space: 510

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: 9b92b2a8-b7e0-11e6-81e4-000c29fa5a95

Master_Info_File: /usr/local/software/mysql-5.6.24-linux-glibc2.5-x86_64/data/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

如果其中Slave_IO_Running: NO,并且日志文件报错:

2016-12-02 11:19:37 19637 [ERROR] Slave I/O: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: 1593

那么修改data目录下的auto.cnf文件后重启数据库即可解决。

MySQL异步复制的更多相关文章

  1. (5.4)mysql高可用系列——MySQL异步复制(实践)

    关键词:mysql复制,mysql异步复制,mysql传统异步复制 [1]实验环境 操作系统:CentOS linux 7.5 数据库版本:5.7.24 数据库架构:主从复制,主库用于生产,从库用于数 ...

  2. MySQL异步复制、半同步复制详解

    MySQL数据复制的原理图大致如下: 从上图我们可以看出MySQL数据库的复制需要启动三个线程来实现: 其中1个在主服务器上,另两个在从服务器上.当发出START SLAVE时,从服务器创建一个I/O ...

  3. 你遇到过哪些原因造成MySQL异步复制延迟?

    master上多为并发事务,salve上则多为单线程回放(MySQL 5.7起,支持真正的并行回放,有所缓解) 异步复制,本来就是有一定延迟的(否则也不叫做异步了,介意的话可以改成半同步复制) sla ...

  4. MySQL异步复制-加强版

    准备:主备库版本一致,主从库正常安装软件. 1.主库上设置一个复制使用的账户: mysql> grant replication slave,replicate client on *.* to ...

  5. MySQL异步复制延迟解决

    http://www.ttlsa.com/mysql/mysql-5-7-enhanced-multi-thread-salve/

  6. 【3.1】【mysql基本实验】mysql复制(主从复制/异步复制/半同步复制,一主一从)

    关键词:mysql复制(异步复制),mysql异步复制 核心原理: mysql 复制流程原理 一个事务在 mysql异步复制中的流程与生命周期 一个事务,在传统半同步的复制流程 #mysql主从基本实 ...

  7. mysql主从复制的异步复制与同步复制

    异 步复制:MySQL本身支持单向的.异步的复制.异步复制意味着在把数据从一台机器拷贝到另一台机器时有一个延时 – 最重要的是这意味着当应用系统的事务提交已经确认时数据并不能在同一时刻拷贝/应用到从机 ...

  8. MySQL异步、同步、半同步复制

    异步复制 MySQL复制默认是异步复制,Master将事件写入binlog,提交事务,自身并不知道slave是否接收是否处理: 缺点:不能保证所有事务都被所有slave接收. 同步复制 Master提 ...

  9. 1018关于MySQL复制搭建[异步复制和半同步复制]

    转自:http://www.cnblogs.com/ivictor/p/5735580.html 搭建MySQL数据库的主从架构,还是蛮简单的.重要的几个命令整理一下. 主从服务器上: SHOW VA ...

随机推荐

  1. POJ 3258 River Hopscotch(二分法搜索)

    Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...

  2. GSAP JS基础教程--TweenLite操作元素的相关属性

    今天来学习用TweenLite操作元素的各种属性,以Div为例,其他元素的操作也是一样的,只是可能一些元素有它们的特殊属性,就可能不同罢了.   代码里用详细注释,我就不再重复啦,大家看代码就可以啦! ...

  3. GitLab 使用

    命令行界面的基本操作如下,Web界面的操作参考:https://www.cnblogs.com/pzk7788/p/10291378.html [root@localhost ~]$ gitlab-c ...

  4. 使用pyinotify监控文件系统的变化

    pyinotify依赖Linux内核inotify功能,它需要在2.6.13版本的内核的Linux系统上运行. 1. 安装pyinotify pip install pyinotify 安装完后可以直 ...

  5. [OSX] 使用 MacPorts 安装 Python 和 pip 指南

    Mac OS 未预装任何在 Unix/Linux 中常见的命令行包管理工具,Mac OS 中的 App Store 和自身的软件升级功能可以下载更新许多比较好的应用,但这些应用多数是满足普通消费者需求 ...

  6. 集群瓶颈为什么是磁盘io

    阅读本文思考: 1.对磁盘IO了解多少 2.为什么是磁盘IO是瓶颈,有没有自己的答案 想了解磁盘io可以查看此帖:集群瓶颈:磁盘IO必读 (磁盘IO:磁盘输出输出) 集群的瓶颈提出多种看法,其中网络和 ...

  7. flask路由中增加正则表达式

    #coding=utf-8 from flask import Flask from werkzeug.routing import BaseConverter class RegexConverte ...

  8. 【truffle】Error: `truffle init` no longer accepts a project template name as an argument.

    下载范例工程时候.使用命令报错 truffle init webpack 错误如下: Error: `truffle init` no longer accepts a project templat ...

  9. 【大数据系列】在hadoop2.8.0下配置SecondaryNameNode

    修改namenode上的hdfs-site.xml configuration> <property> <name>dfs.replication</name> ...

  10. dos 下如何查看环境变量

    使用命令:echo %path%