如果是两个不同数据库放在同一台机器上数据库A,数据库B:
数据库A.a表用到数据库B.b表中的外键,可以用:
A表:
 KEY pubClassId (pubClassId),
   CONSTRAINT pubfield_pubfk_1 FOREIGN KEY (pubClassId) REFERENCES B.b (id)
这样B.b来表示,那如果B表在其他服务器上,该如何实现,是否需要写上服务器B的IP和数据库用户名密码? 谢谢。

解决方案 »

  1.   

    同步是不是跟分开放不一样? 我的需求是想A库放在服务器1上,B库房在服务器2上,A库中的a表中有外键关联到B库中B表主键。
      

  2.   

    先将服务器2上做一个A库的从库,此时A的从库和B库在服务器2的一个实例上
      

  3.   

    谢谢楼上,我按照这个帖子说的方法:
    http://www.cnblogs.com/lben/archive/2012/11/19/2777632.htmlslave一直显示:mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.1.120
                      Master_User: admin
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: log.000001
              Read_Master_Log_Pos: 328
                   Relay_Log_File: chengxin-relay-bin.000005
                    Relay_Log_Pos: 277
            Relay_Master_Log_File: log.000001
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                  Replicate_Do_DB: mydb
              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: 328
                  Relay_Log_Space: 453
                  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: 78622a0b-5aa9-11e3-920d-81201f3cd05f
                 Master_Info_File: /var/lib/mysql/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)ERROR: 
    No query specified
    主服务端那边也是启动的(设置了mydb),但是从服务器一直没同步数据,请问可能是什么原因?谢谢。
      

  4.   

    我现在的方案是冷备份,先lock然后到出数据,从机再进行source.然后主机再unlock.