从同一个mysql服务器的不同数据库复制表

时间:2011-11-12 13:24:04

标签: mysql replication

我有一台带有2个数据库的服务器,我想将几​​个表从一个数据库复制到另一个数据库。目的是我们使用项目中使用的相同用户表。

正如在其他表中使用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同步表并启动slave 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 'root@localhost: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

事情是主更改不会影响从属,但是从属状态会发生变化。

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

3 个答案:

答案 0 :(得分:1)

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

Slave未更新,因为 server-id 对于主服务器和从服务器都是相同的。通常,slave会忽略具有与其自身相同的server-id的更新。

replicate-same-server-id 添加到my.cnf。 replicate-same-server-id documentation

答案 1 :(得分:1)

出于兴趣,一个观点可以做你想要的吗?

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

如果服务器硬件出现问题,您可能想要调查的另一个选项是运行在同一台计算机上运行不同端口的多个mysql实例,这可能有助于您实现所需的目标。这是我在测试环境中用于模拟主数据库故障和从数据库升级的内容。

答案 2 :(得分:0)

例如,在许多情况下您可以实现更多优化。 DB1复制到DB2(同一服务器)。从DB2那里只存储数据长达1周。删除所有超过1周的数据(在db2上)。在这样的设置中,例如高流量数据库服务器,你需要它尽可能干净,同一服务器上的双数据库设置使用来自服务器的“更少”资源,如果你的服务器大多数时间做的是从中读取数据数据库。我有这样的设置但我使用4个不同的服务器。服务器1)3天。服务器2)30天。服务器3)2个月,服务器4从开始的所有数据。 (服务器4主要用于那些非常旧的寄存器,没有那么多使用。对不起我的英文但我认为我指出了你可以在哪里,并应该在同一台服务器上使用数据库复制来减少内存使用和CPU使用。

相关问题