2011-11-12 43 views
4

我有一个服务器与2个数据库,我想复制几个表从一个数据库到另一个。目的是我们使用项目中使用的同一个用户表。从同一个mysql服务器的不同数据库复制表

由于在他人的表中使用InnoDB与用户表的外键我选择了复制方式。

对于我为的my.cnf

master-user=root 

server-id      = 2 
replicate-rewrite-db   = dou->jobs 
replicate-do-table    = jobs.auth\_user 
replicate-wild-do-table   = jobs.geo\_% 
replicate-do-table    = jobs.user\_profile 
replicate-same-server-id  = 1 
report-host      = master-is-slave 

binlog-do-db     = dou 

log-bin 

的变化从binlog-do-db同步表和开始从error.log中下一行之后出现:

111112 15:10:22 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='localhost', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='localhost', master_port='3306', master_log_file='mysql-bin.000074', master_log_pos='106'. 
111112 15:10:36 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000074' at position 106, relay log '/var/log/mysql/dell-relay-bin.000001' position: 4 
111112 15:10:36 [Note] Slave I/O thread: connected to master '[email protected]:3306',replication started in log 'mysql-bin.000074' at position 106 

似乎,关于该步骤的一切是好吧,show slave status显示没有错误。

mysql> show slave status\G; 
*************************** 1. row *************************** 
       Slave_IO_State: Waiting for master to send event 
        Master_Host: localhost 
        Master_User: root 
        Master_Port: 3306 
       Connect_Retry: 60 
       Master_Log_File: mysql-bin.000074 
      Read_Master_Log_Pos: 814 
       Relay_Log_File: dell-relay-bin.000002 
       Relay_Log_Pos: 959 
     Relay_Master_Log_File: mysql-bin.000074 
      Slave_IO_Running: Yes 
      Slave_SQL_Running: Yes 
       Replicate_Do_DB: 
      Replicate_Ignore_DB: 
      Replicate_Do_Table: jobs.user\_profile,jobs.auth\_user 
     Replicate_Ignore_Table: 
     Replicate_Wild_Do_Table: jobs.geo\_% 
    Replicate_Wild_Ignore_Table: 
        Last_Errno: 0 
        Last_Error: 
       Skip_Counter: 0 
      Exec_Master_Log_Pos: 814 
       Relay_Log_Space: 1113 
       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: 
1 row in set (0.00 sec) 

ERROR: 
No query specified 

事情是,主变更不会影响奴隶,但奴隶状态的变化。

感谢您解决这个问题的任何帮助。

回答

1

我不会告诉你,复制表到同一数据库是坏主意,几次因增加IO。

从站未更新,因为服务器标识对于主站和从站都是相同的。通常,slave会使用与自己相同的server-id来忽略更新。

添加重复,同一服务器ID到my.cnf文件。 replicate-same-server-id documentation

+0

_将replicate-same-server-id添加到my.cnf。 replicate-same-server-id documentation_ 感谢您的回答,我在my.cnf中有这个选项 –

+0

抱歉,还没有检查过它。 “SHOW VARIABLES”讲述了什么?它是否设置?应用更改后是否重新启动了服务器? – mente

+0

[replicate-rewrite-db](http://dev.mysql.com/doc/refman/5.5/en/replication-options-slave.html#option_mysqld_replicate-rewrite-db):_数据库名称转换是在--replicate- *规则已经过测试。[服务器如何评估复制过滤规则](http://dev.mysql.com/doc/refman/5.5/en/replication-rules.html):_后者的示例可能会产生意想不到的效果是同时使用--replicate-do-db和--replicate-wild-do-table,其中--replicate-wild-do-table使用的数据库名称模式与给定的名称匹配--replicate-do-db_ – mente

1

出于兴趣就会有意见做你想做的事情?

我真的不认为运行在MySQL的同一实例复制到同一个实例是一个好主意。

你可能要调查,如果服务器硬件出了问题,将运行MySQL的多个实例在同一台机器,这可能会帮助你实现你在找什么上运行过不同端口的其他选项。这是我在测试环境中使用的模拟主DB故障和从DB升级。

0

有你在哪里可以achive更多的优化,例如许多情况下。 DB1复制到DB2(同一台服务器)。 DB2从哪里存储数据的时间长达1周。所有超过1周的数据都会被删除(在db2上)。在这样的设置中,例如一个高流量的数据库服务器,你需要尽可能的干净,同一台服务器上的双数据库设置使用来自服务器的“少”资源,如果你的服务器大部分时间做的是从数据库。我有这样的设置,但我使用4个不同的服务器。服务器1)3天。服务器2)30天。服务器3)2个月,服务器4从开始的所有数据。 (服务器4主要用于见Gething很老的寄存器没有那么多的使用。对不起,我的英语buth我认为我做了,你可以而且应该使用同一服务器上的数据库复制,以减少memmory使用和CPU使用率点。

0

@mente建议,server_is不能相同

一个解决方案是运行一个不同的服务器,并配置它们来复制所需的数据库我建议去Galera集群,因为它遵循同步复制和多主控拓扑。由于这个原因,节点之间的复制将不会出现滞后和其他许多优点。

另一种解决方案是通过在午夜运行同步作业(当没有活动的开发时)来保持数据库的同步。您还可以尝试使用具有用于安排同步作业的GUI工具的SQLyog。

相关问题