MySQL 复制单个表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2962721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:11:18  来源:igfitidea点击:

Replicate a single table

mysqlreplicationdatabase-schema

提问by shantanuo

Is it possible to replicate a single table?

是否可以复制单个表?

采纳答案by halfdan

Yes this is possible. Have a look at the slave optionsof the MySQL manual. This still requires to create a complete binlog of the whole database though.

是的,这是可能的。看看MySQL 手册的slave 选项。尽管如此,这仍然需要创建整个数据库的完整二进制日志。

回答by Rainer Stumbaum

To sync specific tables again to one or more slaves rather use pt-table-checksum and then pt-table-sync

要将特定表再次同步到一个或多个从属设备,请使用 pt-table-checksum 和 pt-table-sync

That should automatically identify the out-of-sync tables and only sync those.

这应该自动识别不同步的表并只同步那些。

回答by Scarecrow

I know this is an old question but this is for anyone who comes here looking for an answer:

我知道这是一个老问题,但这是为任何来这里寻找答案的人准备的:

CREATE TABLE table2 LIKE table1;

This will create a table with the same format and columns but no data. To transfer the data use:

这将创建一个具有相同格式和列但没有数据的表。传输数据使用:

INSERT INTO table2 SELECT * FROM table1;

EDIT:

编辑:

It is important to note that this is an information transfer only. Meaning if you had indexes on table1 they are not transferred to table2. You will have to manually index table2

需要注意的是,这只是一种信息传输。这意味着如果您在 table1 上有索引,它们不会传输到 table2。您将不得不手动索引 table2