简体   繁体   English

同步两个MySQL表

[英]Sync two MySQL tables

Have two separate databases. 有两个单独的数据库。 The master that holds the user information(username, password, address etc.). 拥有用户信息(用户名,密码,地址等)的主机。 The slave database only has one table where the user name and password. 从属数据库只有一个表,其中包含用户名和密码。 I would like to happen is then an new user on the master db i created that the username and password is also added to the slave db. 我想发生的是,然后我在主数据库上创建了一个新用户,该用户名和密码也添加到了从数据库中。

You can do this with either a TRIGGER or STORED PROCEDURE . 您可以使用“ 触发”或“ 存储过程”来执行此操作。

In your case i guess you could use something like this (not tested): 在您的情况下,我想您可以使用类似以下内容(未经测试):

CREATE TRIGGER `user_update` AFTER INSERT ON `User` 
FOR EACH ROW 
BEGIN
    INSERT INTO `mydb`.`UserLogin` (`id`, `UserName`, `Pass`) 
    VALUES (new.UserId, new.UserName, new.Password);
END$$

We face a similar situation. 我们面临着类似的情况。 We use Percona Toolkit's pt-table-sync tool. 我们使用Percona Toolkit的pt-table-sync工具。 It's rather simple to use. 使用起来很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM