gpt4 book ai didi

mysql - 更换 table 的正确方法是什么?

转载 作者:行者123 更新时间:2023-11-29 11:54:57 27 4
gpt4 key购买 nike

我有一个 MySQL 数据库 mydb 和一个测试环境中的数据库 mytestdb,它镜像 mydb。我需要一种将更改从测试数据库“推送到实时数据库”的方法。所以伪代码的过程就像

for each table T in mydb
delete all from T
T' = corresponding table in mytestdb
for each row R in T'
insert R in T

或者我应该以不同的方式执行该过程?此设置有任何潜在问题吗?

最佳答案

A计划:

DROP TABLE x;
Create and Load its replacement.

B 计划(更适合在实时情况下重新加载表格):

CREATE TABLE new LIKE real;
LOAD TABLE new ... -- slowest step
RENAME TABLE real TO old, new TO real; -- atomic and 'instantaneous'
DROP TABLE old;

关于mysql - 更换 table 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33355346/

27 4 0