摘要

  一、MySQL Replication

      介绍MySQL Replication的基本概念,摘自于Mysql官网

  二、Replication Configuration

     2.1 Basic Steps in Configuration

      

一、MySQL Replication

1. What is Replicaiton?

  For the purposes of this article we define "Replication" as the duplication of data to one or more locations.

  These can be co-located within a data center, or geographically distributed.

  Replication enables a database to copy or duplicate changes from one physical location or system to another.

  note:

    •  Replication is relatively good for scaling reads, which you can direct to a slave, but it's not a good way to scale writes unless you design it right
    •  Attaching many slaves to a master simple causes the writes to be done, once on each slave
    •  Replication is also wasteful with more than a few slaves, because it essentially duplicated a lot of data needlessly.

  

2. Problems Solved by Replication

    note:MySQL's replication is usually not very bandwidth-intensive, and you can stop and start it at will

  • Load balancing: Distribute read queries across serveral servers, which works very wll for read-intensive applications.
  • Backups
  • High availability and failover
  • Testing MySQL upgrades

3. Replication: Master-Slave

概念简要说明:

Binary log: Binary log (二进制日志) is a Set of files :

  •  Contains all writes and schema changes
  •  != REDO/Transaction log
  •  Rotated when full (Set max_binlog_size)
  •  Incrementing numbers (defaults, mysql-bin.000001,0000002,0000003...)
  •  Relay Logs are alo binary logs
  •  With 2 Formats: Statement Based(SBR), Row based(RBR, since mysql5.1)

Relay log: 中继日志

Binlog Dump Thread:

  To send the binary logcontens to the slave.

  A master that has multiple slaves "attached" to it creates one binlog dump thread for each currently connected slave, "with each slave having its own I/O and SQL threads."

Slave I/O Thread:

  A START SLAVE statement creates an I/O thread, which connects to the master and asks it to send the updates recorded in its binary logs

Slave SQL Thread:

  To read the relay logs that were written by the slave I/0 thread and executes the updates contained in the relay logs

  If using multi-threaded slaves, mutiple SQL threads will be created on the slave.

4. Replication Modes and Data Consistency

  • Asynchronous Replication:  By default, MySQL is asynchronus.

    Updates are committed to the database on the master and than relayed(重播,转发) to the slave where they are also applied.

  The master does not wait for the slave to receive the update, and so is able to continue processing further write operations without as it waits for acknowledgement from the slave.

  

  • Semi-Synchronous Replication

    Using semi-synchronous replication, a commit is returned to the client only when a slave has received the update, or a timeout occurs.

    Therrfore it is assured that the data exists on the master and at least one slave (note that the slave will have received the update but not necessarily applied it when a commit is returned to the master).

5. MySQL Replication workflow

二、Replication Configuration

2.1 Basic Steps in Replication

step1: Configure one server to be a master

step2: Configure one server to be a slave

step3: Connect the slave to the master

(1) Configure one server to be a master

 To configure a server so that it can act as master, ensure the server has an active binary log and a unique server ID.

  The Server ID is used to distinguish two servers from each other.

  To set up the binary log and Server ID, you have to take the server down and add the log-bin,log-bin-index and server-id options to the my.cnf configuration file.

notes:

  1. It is not necessary to give a name in the log-bin option, The default value is hostname-bin;

  2. It is a good idea to create a name that is unique server and not tied to the machine the server is running on, since it can be confusing to work with a series of binlog files that suddenly change name midstream;

  3. Each server is identified by a unique server ID;

(2) Creating Replication Accounts

  Must create a user account on the master and give it the proper privileges, so the I/O thread can connect as  that user and read the master's binary log

  

(3) Configuration the Slave

  server ID also

   you may also want to consider adding the names of relay log and the relay log index files to the my.cnf file using the options relay-log and relay-log-index

 

(4) Connecting the Master and Slave

Final step: directing the slave to the master so that it knows where to replicate

 It also lets you point the slave at a different master  in the future, without stopping the server.

(5) Monitoring Replication

(6) Watching Replication in Action

Event_type:

  This is the type of the event.

Server_id:

  This is the server ID of the server that created the event

Log_name;

  The name of the file that stores the event

Pos:

  This is the position of the file where the event starts; that is, it's the first byte of the event/

End_log_pos:

  This gives the position in the file where the event ends and the next event starts

Info:
  This is human-readable text with information about the event.

MySQL Replicationation基础的更多相关文章

  1. mysql使用基础 sql语句(一)

    csdn博文地址:mysql使用基础 sql语句(一)  点击进入 命令行输入mysql -u root -p,回车再输入密码,进入mysql. 终端命令以分号作为一条语句的结束,可分为多行输入,只需 ...

  2. mysql数据库基础的简单操作指南

    最近在学习mysql,本文是做的关于mysql学习的笔记,跟大家分享一下,希望对大家学习mysql知识有所助益.mysql现在几乎已经成了网站建设的主流数据库,很多php网站系统都采用了mysql数据 ...

  3. Mysql索引基础

    Mysql索引基础 基本概念: 索引是一种特殊的数据库结构,可以用来快速查询数据库表中的特定记录.索引是提高数据库性能的重要方式.索引创建在表上,是对数据库表中一列或多列的值进行排序的一种结构.可以提 ...

  4. MySQL Replicationation进阶

    摘要 上一篇: MySQL Replication 基础  下一篇 MySQL Replication-MHA 一.主主复制 二.半同步复制 三.复制过滤器 四.总结 五.切分 待续 一.主主复制 M ...

  5. MySQL数据库基础

    MySQL数据库基础 本文的所有操作是基于CMD环境,MySQL通过在命令行中输入SQL语句对数据库进行操作.配置问题可参考<打通MySQL的操作权限>中的内容,该文算是针对前期的环境配置 ...

  6. Mysql数据库基础学习笔记

    Mysql数据库基础学习笔记 1.mysql查看当前登录的账户名以及数据库 一.单表查询 1.创建数据库yuzly,创建表fruits 创建表 ) ) ,) NOT NULL,PRIMARY KEY( ...

  7. 2.Mysql SQL基础

    2.Mysql SQL基础2.1 SQL简介 SQL(Structure Query Language)是结构化查询语言.2.2 SQL使用入门 2.2.1 SQL分类 SQL分为DDL.DML(DQ ...

  8. 【笔记】MySQL的基础学习(二)

    [笔记]MySQL的基础学习(二) MySQL 老男孩  一 视图 视图其实就是给表起个别名 1.创建视图 格式:CREATE VIEW 视图名称 AS SQL语句 CREATE VIEW v1 AS ...

  9. 【笔记】MySQL的基础学习

    [笔记]MySQL的基础学习 老男孩 MySQL  一 安装与配置 1 下载安装 官网:http://dev.mysql.com/downloads/mysql/ 下载相应版本的压缩包 解压压缩包至任 ...

随机推荐

  1. CODE[VS]-判断浮点数是否相等-浮点数处理-天梯青铜

    题目描述 Description 给出两个浮点数,请你判断这两个浮点数是否相等 输入描述 Input Description 输入仅一行,包含两个浮点数 输出描述 Output Description ...

  2. get与post请求

    1.post请求 如果表单以Post方式提交过来的,接收时必须以Requert.Form来接收,并且表单元素必须有name属性,而Form指定的键的名称就是name属性的值 <form meth ...

  3. 那些年,我们被耍过的bug——haslayout

    你被IE的bug耍过几次了? IE,这个令所有网站设计人员讨厌,但又不得不为它工作的浏览器.不论是6.7还是8,它们都有一个共同的渲染标准haslayout,所以haslayout 是一个非常有必要彻 ...

  4. 清理SharePoint 2010的SQL Server 2008 R2日志数据库的方法!

    //来源:http://www.cnblogs.com/nbpowerboy/p/3380079.html 公司用SharePoint 2010已有三年多的时间了,上BPM项目也有2年多的时间,之前供 ...

  5. js输入框对金额的匹配

    /** * 金额格式化 * @param s * @param n * @returns {String} */ function fmoney(s, n) { n = n > 0 && ...

  6. c#中,委托Func的简单实践

    c# 委托Func的简单实践最近才真正的接触委托,所以针对Func类型的委托,做一个实践练习. 首先说一些我对委托的初级理解:"就是把方法当做参数,传进委托方法里". 我平时用到的 ...

  7. many bugs report when test bcm bt/wifi chip

    after change aerial  , many bugs diappear .

  8. JS算法与数据结构之八皇后(晕晕)

    算法核心思想 回溯算法 递归实现 程序实现 坐标系 循环递归 回溯 计数 收集位置 特效添加 <!DOCTYPE HTML> <html> <head> <m ...

  9. Learning from the CakePHP source code - Part I

    最近开始痛定思痛,研究cakephp的源码. 成长的路上从来没有捷径,没有小聪明. 只有傻傻的努力,你才能听到到成长的声音. 下面这篇文章虽然过时了,但是还是可以看到作者的精神,仿佛与作者隔着时空的交 ...

  10. date格式化

    Linux: [ghsea@localhost ~]date +%Y:%m:%d [ghsea@localhost ~]date +%Y-%m%d [ghsea@localhost ~]date +% ...