How to update a table automatically as another table is updated on different mysql server?

前端 未结 2 447
南方客
南方客 2021-01-23 13:28

Let\'s say I have two databases \'db1\' & \'db2\' on different mysql servers \'A\' & \'B\' respectively.

I want to check every 6 hours if there is any update fou

相关标签:
2条回答
  • 2021-01-23 13:36

    You could do with with a cron job, simply could run a php file every minute.

    this file can check for a new row in a table1 in db2 (saving current count of rows in a text file for comparison, and if new count > old count, then this can then update table1 in db1.

    easy

    but mysql replication as @Charles said in the comment would be better.

    0 讨论(0)
  • 2021-01-23 13:58

    I accepted kutF's answer and after you run that program Using keyword CASCADE in table creation in mysql. So if you update the parent table then the child table also get updated

    CREATE TABLE parent
    (
    par_id INT NOT NULL,
    PRIMARY KEY (par_id)
    ) TYPE = INNODB;
    
    CREATE TABLE child
    (
    par_id INT NOT NULL,
    child_id INT NOT NULL,
    PRIMARY KEY (child_id),
    FOREIGN KEY (par_id) REFERENCES parent (par_id) ON DELETE CASCADE
    ) TYPE = INNODB;
    
    0 讨论(0)
提交回复
热议问题