如何使用MySQL在db2中引用db1中的外键

时间:2016-10-09 06:34:07

标签: mysql

我有两个MySQL数据库:masterslavemaster db包含memberid字段。如何在memberid db中引用slave?这是我尝试使用slave db但没有成功的原因:

DROP TABLE IF EXISTS `attend_date_temp`;
CREATE TABLE `attend_date_temp` (
`clientid` int(10) unsigned NOT NULL,
`groupid` int(10) unsigned NOT NULL,
`memberid` int(10) unsigned NOT NULL,
KEY `clientid` (`clientid`),
KEY `memberid` (`memberid`),
CONSTRAINT `attend_date_temp_ibfk_1` FOREIGN KEY (`clientid`) REFERENCES `clients` (`clientid`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `attend_date_temp_ibfk_2` FOREIGN KEY (`memberid`) REFERENCES `master.members` (`memberid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8

当我在该表中查看memberid外键时,收到此消息:

Table 'slave.master.members' doesn't exist.

有人可以告诉我我做错了什么吗? This is the reference I used. 感谢。

1 个答案:

答案 0 :(得分:1)

T a[n]

应该是:

REFERENCES `master.members`

否则,它会尝试在REFERENCES `master`.`members` 数据库中找到一个名为master.members的表。