MySQL异步复制

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

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,端口以及开始进行复制的日志文件和位置等,具体如下:

wps58F2.tmp

本次试验脚本如下:

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文件后重启数据库即可解决。

转载于:https://www.cnblogs.com/wcwen1990/p/6655329.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393317.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

开源一个爬取redmine数据的测试报告系统

背景 软件测试的最后有一道比较繁琐的工作,就是编写测试报告。手写测试报告在数据统计和分析上面要耗费比较大的事件和精力。之前工作室使用mantis管理bug缺陷。公司有内部有个系统,可以直接从mantis上面获取数据并进行统计,生成一份测试报告…

java cxf 双向通讯_CXF 在spring boot 2 发布多个服务

0. 问题来源之前配置cxf服务端都是在spring 3以下,后来使用spring mvc 还都是基于xml的配置文件模式,在springboot模式下,实现起来更为简单了。此次记录下spring boot 2下的实现方式。1. 准备工作项目中,直接拉入spring boot cxf相…

小程序 坚屏_如何构建坚如磐石的应用程序

小程序 坚屏不同的应用程序设计选项概述 (An overview of different app design options) When we design software, we constantly think about error cases. Errors have a huge impact on the way we design and architecture a solution. So much so, in fact, that there …

C# 分层

三层架构分为:表现层(UI)、业务逻辑层(BLL)、数据访问层(DAL)再加上实体类库(Model) 转载请注明出自朱朱家园http://blog.csdn.net/zhgl7688 1、实体类库(Mod…

leetcode1177. 构建回文串检测(前缀和)

给你一个字符串 s,请你对 s 的子串进行检测。 每次检测,待检子串都可以表示为 queries[i] [left, right, k]。我们可以 重新排列 子串 s[left], …, s[right],并从中选择 最多 k 项替换成任何小写英文字母。 如果在上述检测过程中&#xf…

java界面化二叉排序树_层次序创建二叉树(图形界面和控制台输入实现)

1 2018.11.72 XT34 /**5 * 功能:构造二叉树6 * 说明:7 * 1.主函数输入模式有两种,BT参数 true 图形界面,false 控制台输入8 * 2.构造树是按层次遍历结果输入的 如:ABCDE*F**GH9 */1011 import javax.swing.*;12 import…

web开发环境_Web开发人员的开发环境

web开发环境With all the tools and programs available, it can be challenging to figure out the best way to set up your development environment on your computer.使用所有可用的工具和程序,寻找在计算机上设置开发环境的最佳方法可能是一项挑战。 In this…

使用.net Stopwatch class 来分析你的代码

当我们在调试,优化我们的代码的时候,想知道某段代码的真正的执行时间,或者我们怀疑某段代码,或是某几段代码执行比较慢, 需要得到具体的某段代码的具体执行时间的时候。有一个很好用的类Stopwatch。 Stopwatch 类在 Sy…

Docker 部署 postgresql 与 pgadmin4

Docker快速部署PostgreSQL服务 快速开始 请新建一个目录postgresql,进入目录postgresql,将以下文件保存为docker-compose.yml,然后执行docker-compose up version: 3 services:mydb:image: postgres:11volumes:- db-data:/var/lib/postgresql…

leetcode151. 翻转字符串里的单词

给定一个字符串&#xff0c;逐个翻转字符串中的每个单词。 示例 1&#xff1a; 输入: “the sky is blue” 输出: “blue is sky the” 代码 class Solution {public String reverseWords(String s) {int ns.length(),i0;ArrayList<String> arrayListnew ArrayList<…

java衍生作用_java-如何从AffineTransform衍生的形状对象中“...

您可以使用AffineTransform.transform(Point2D, Point2D)变换多边形上的单个点.如果您不使用旋转变换来移动船,而是将船的位置保持在一个(x,y)位置,那么事情就简单得多.您可以在move()中移动飞船的位置,而不是尝试平移多边形.然后,当您想给船上油漆时,例如做&#xff1a;// Opt…

初学者设计数据库_面向初学者的完整数据库设计课程

初学者设计数据库This database design course will give you a deeper grasp of database design. Caleb Curry teaches the equivalent of an entire college course during this eight hour video.本数据库设计课程将使您更深入地了解数据库设计。 在这8个小时的视频中&…

Qt QTcpSocket使用总结

socket的连接是异步的&#xff0c;所以必须等连接建立完成才能使用&#xff0c;所以分别加入waitForConnected()和waitForBytesWritten()后调试通过1&#xff09;只有使用waitForConnected()后,QTcpSocket才真正尝试连接服务器&#xff0c;并返回是否连接的结果2&#xff09;避…

[bzoj1303][CQOI2009]中位数图

来自FallDream的博客&#xff0c;未经允许&#xff0c;请勿转载&#xff0c;谢谢。 给定一个n个数排列&#xff0c;求有多少段长度为奇数的区间&#xff0c;中位数是b. n<100000 时间限制0.1s 我一开始没看到排列&#xff0c;想着怎么还能O(n)做的啊&#xff1f;&#xff1f…

falsk 请求没有返回值报错

线上报警 5xx 错误&#xff0c;查看日志发现报这个错&#xff0c; TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement. 这个方法没有有效的返回结果 页面报这个错误 Internal Server Err…

java的iterator接口_java Iterator接口和LIstIterator接口分析_java_脚本之家

java Iterator接口和LIstIterator接口分析目录1.Iterator接口2.ListIterator3.Iterator和ListIterator的区别正文在继续看ArrayList源码之前&#xff0c;先了解Iterator接口和ListIterator接口&#xff0c;下篇文章详细讲解ArrayList是如何实现它们的。我们知道&#xff0c;接…

leetcode468. 验证IP地址

编写一个函数来验证输入的字符串是否是有效的 IPv4 或 IPv6 地址。 IPv4 地址由十进制数和点来表示&#xff0c;每个地址包含4个十进制数&#xff0c;其范围为 0 - 255&#xff0c; 用(".")分割。比如&#xff0c;172.16.254.1&#xff1b; 同时&#xff0c;IPv4 地…

播客#45:迪伦·以色列

On todays episode, I interview Dylan Israel. Dylan is a software engineer, a YouTuber, and the creator of several programming courses.在今天的一集中&#xff0c;我采访了迪伦以色列。 迪伦(Dylan)是一位软件工程师&#xff0c;一名YouTuber&#xff0c;并且是几门编…

PHPstorm快捷键

当前文件搜索类&#xff1a;ctrln 全文检索文件&#xff1a;ctrlshiftn 收起侧边栏&#xff1a;alt1&#xff08;自定义&#xff09; 个人学习记录&#xff0c;持续更新中。。。 转载于:https://www.cnblogs.com/zaijiang/p/7806260.html

JS基础_强制类型转换-Number

https://www.cnblogs.com/ZHOUVIP/p/7225267.html转载于:https://www.cnblogs.com/robinunix/p/11011188.html