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

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. 实战c++中的string系列--不要使用memset初始化string(一定别这么干)

    參考链接: http://www.cppblog.com/qinqing1984/archive/2009/08/07/92479.html 百度百科第一次这么给力: void *memset(voi ...

  2. mongodb 按照时间聚类 java

    当存储到mongodb中的是string类型的时间,小tips: 1. 那么在对此域按照时间聚类(每周,每月)时就不能直接使用mongodb的time关键字了,因为mongodb有自己的时间类型,且目 ...

  3. mongodb命令(1)

    成功启动MongoDB服务后,打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显 ...

  4. iOS开发--UIButton 设置圆角 边框颜色 点击回调方法

    UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom]; signBtn.frame = CGRectMake(, , , ) ...

  5. HTML 格式化

    格式化标签: <!DOCTYPE HTML> <html> <body> <b> This text is bold </b> # < ...

  6. curses.h: No such file or directory

    嵌入式linux移植时,编译busybox或者内核时使用make menuconfig有时会遇到这个错误 Linux Error: ncurses.h: No such file or directo ...

  7. Java的I/O操作

    一.概述 Java的IO支持通过java.io包下的类和接口来完成,在java.io包下主要有包括输入.输出两种IO流,每种输入输出流又可分为字节流和字符流两大类.从JDK1.4以后,Java在jav ...

  8. iOS - UICollectionView 瀑布流 添加表头视图的坑

    UICollectionView 瀑布流 添加表头视图的坑 首先是,需求加了个头视图在顶部,在collectionView中的头视图跟TableView的不一样,TableView的表头只要设置tab ...

  9. linux源码编译安装php出现 cannot find -lltdl

    原因: 在编辑php时添加的“–with-mcrypt”选项造成. 解决方法: 1.如果不需要mcrypt,那么编辑php时去掉该选项,然后再make.make install. 2.如果需要mcry ...

  10. thinkphp3.2 实现留言功能

    写一个例子说明一下: 前端:http://www.mmkb.com/zhendao/index/feedback.html <form method="post" actio ...