replicate-rewrite-db:

  1. Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it was from_name on the master.Only statements involving tables are affected (not statements such as CREATE DATABASE, DROP DATABASE, and ALTER DATABASE), and only if from_name is the default database on the master.This does not work for cross-database updates.To specify multiple rewrites, use this option multiple times.The server uses the first one with a from_name value that matches.The database name translation is done before the --replicate-* rules are tested.
  2. If you use this option on the command line and the “>” character is special to your command interpreter, quote the option value.For example:
  3. shell> mysqld --replicate-rewrite-db="olddb->newdb"
比如,master与slave同步fandb这个库,但因为需要slave需要将fandb改名为dudb,master不能改,就需要这个参数
在Slave端的my.cnf中加入
replicate-rewrite-db=fandb->dudb

重启Slave库,然后首先要创建dudb这个库

加入Master端执行

  1. (mysql@localhost)[fandb]> create table rewrite asselect*from ab;
如果Slave没有dudb.ab这个表,就会报错
  1. [ERROR]Slave SQL:Error'Table 'dudb.ab' doesn't exist' on query. Default database: 'dudb'. Query: 'create table rewrite as select * from ab', Error_code: 1146
  2. 2015-07-10 09:44:58 48962 [Warning] Slave: Table 'dudb.ab' doesn't exist Error_code:1146
  3. 2015-07-1009:44:5848962[ERROR]Error running query, slave SQL thread aborted.Fix the problem, and restart the slave SQL thread with "SLAVE START".We stopped at log 'mysql-bin.000003' position 3973
然后sql_thread也会被停止
  1. mysql> show slave status\G
  2. ***************************1. row ***************************
  3. Slave_IO_State:Waitingfor master to send event
  4. Master_Host:192.168.134.132
  5. Master_User: repl
  6. Master_Port:3306
  7. Connect_Retry:60
  8. Master_Log_File: mysql-bin.000003
  9. Read_Master_Log_Pos:4089
  10. Relay_Log_File: mysql-relay-bin.000002
  11. Relay_Log_Pos:283
  12. Relay_Master_Log_File: mysql-bin.000003
  13. Slave_IO_Running:Yes
  14. Slave_SQL_Running:No
这时需要手动create table dudb.ab as select * from fandb.ab
然后在start slave sql_thread
如果有多个库需要换名字,那么需要多次指定这个参数 
replicate-rewrite-db=fandb->dudb
replicate-rewrite-db=a->b

replicate-rewrite-db的更多相关文章

  1. Hadoop 之Mong DB 之CentOS 6 使用 yum 安装MongoDB及服务器端配置

    安装MongoDB的方法有很多种,可以源代码安装,在Centos也可以用yum源安装的方法.由于MongoDB更新得比较快,我比较喜欢用yum源安装的方法.64位Centos下的安装步骤如下: 1.准 ...

  2. phpwind的rewrite重写原理

    没有深入过pw,被人问到这方面的问题,搜索了一下,发现了一篇博文,但原博客已打不开. http://www.phpsoho.com/html/document/200608/1154750694.ht ...

  3. nginx 配置 ThinkPHP Rewrite

    server { listen 80; server_name www.funsion.com; root /www/web/funsion; index index.php; location / ...

  4. trove,测试,db小解析

    # Copyright 2014 Tesora Inc.# All Rights Reserved.## Licensed under the Apache License, Version 2.0 ...

  5. apache、nginx的虚拟域名配置和rewrite配置,以及web缓存的几种方式

    web缓存一般用来缓解数据库压力. 通常有几种方法,文件静态化,缓存服务memcached.redis等. 伪静态,一般指在url上貌似访问静态html页的形式,这样有利于搜索引擎访问到网站页面,实际 ...

  6. The Architecture of Open Source Applications: Berkeley DB

    最近研究内存关系数据库的设计与实现,下面一篇为berkeley db原始两位作为的Berkeley DB设计回忆录: Conway's Law states that a design reflect ...

  7. sqlt 之 分析 DB upgrade 导致SQL 性能下降 的方法 xplore

    https://blog.csdn.net/lukeUnique/article/details/79331779 https://mauro-pagano.com/2014/10/27/when-t ...

  8. Azure Cosmos DB (四) 使用EF的SQL API 异地冗余

    一,引言 上一篇文章中,我们介绍到使用了EF Core 与Cosmos DB SQL API 进行结合开发.同时,大家在开发过程中一定要记得EF Core 不支持Cosmos DB 的迁移.今天我们启 ...

  9. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...

  10. VS15 preview 5打开文件夹自动生成slnx.VC.db SQLite库疑惑?求解答

    用VS15 preview 5打开文件夹(详情查看博客http://www.cnblogs.com/zsy/p/5962242.html中配置),文件夹下多一个slnx.VC.db文件,如下图: 本文 ...

随机推荐

  1. ForeignKey 的第二个位置参数on_delete

    on_delete指的是通过ForeignKey连接起来的对象被删除后,当前字段怎么变化. 常见的选项有: models.CASCADE,对就对象删除后,包含ForeignKey的字段也会被删除 mo ...

  2. JSP三大指令

    JSP三大指令1.page-->最复杂,<%@page language = "java" info = "xxx" ..%>  *pageE ...

  3. JavaScript 基础(七) 箭头函数 generator Date JSON

    ES6 标准新增了一种新的函数: Arrow Function(箭头函数). x => x *x 上面的箭头相当于: function (x){ return x*x; } 箭头函数相当于匿名函 ...

  4. MySQL的数据库无法插入中文是怎么回事?

    插入中文就报错: Incorrect string value: '\xE7\x8F\xBD\xE7\x8F\xBA' for column 'name' at row 1 用set names ut ...

  5. 离线安装VS 2013开发工具的方法!

    目前微软已正式发布了VS 2013的开发工具,但安装VS 2013开发工具前必须安装或升级到IE10,否则无法进行安装.本文主要介绍在Windows Server 2008 R2 SP1下离线安装IE ...

  6. avalon2学习教程09循环操作

    avalon2的循环指令的用法完全改变了.avalon最早期从knockout那样抄来ms-each,ms-with,分别用于数组循环与对象循环.它们都是针对元素内容进行循环.后来又从angular那 ...

  7. smarty模板的安装配置

    第一步:下载Smarty模版源码包了    百度一下“Smarty下载”,下载最新版本的Smarty模版第二部:解压缩,将下载好的Smarty包解压缩    右键->解压到当前文件夹...你懂的 ...

  8. PHP基于SOAP实现webservice

    简单对象访问协议(SOAP)是一种轻量的.简单的.基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息. SOAP 可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议( H ...

  9. 客户端连接linux经常间隔性断开链接

    起因 在使用SecureCRT通过telnet或SSH访问linux时,总是出现过段时间操作就会断开连接提示重连的问题.起初以为是网络不稳定造成的,但我测试发现在服务器端一直可以ping通客户端IP, ...

  10. jQuery数组处理汇总

    jQuery数组处理汇总   有段时间没写什么了, 打算把jquery中的比较常用的数组处理方法汇总一下 $.each(array, [callback])遍历,很常用 1 2 3 4 5 6 7 8 ...