且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

复制重写数据库是否具有任何实际应用程序?

更新时间:2022-11-24 22:10:34

复制-rewrite-db 的用法与其他复制选项相同。 Replication-rewrite-db 不仅可在默认数据库上运行,而且还可以: replicate-do-db,replicate-ignore-db,binlog- do-db和binlog-ignore-db 。请参考

Replication-rewrite-db usage is same as other replication options. Not only Replication-rewrite-db works on the default database, but these also: replicate-do-db, replicate-ignore-db, binlog-do-db and binlog-ignore-db. Refer this and this.

这是现实生活中的用途,否则MySQL不会实现此选项。而且它仅适用于默认数据库因为 -

There are real world purpose, else MySQL wouldn't have implemented this option. And it works only on default database because-


仅检查默认数据库行为的主要原因是
,仅凭语句就很难知道是否应该复制
(例如,如果您正在使用跨
多个数据库运行的多表
DELETE语句或多表UPDATE语句)。如果不需要,仅检查默认的
数据库而不是所有数据库也更快。

The main reason for this "check just the default database" behavior is that it is difficult from the statement alone to know whether it should be replicated (for example, if you are using multiple-table DELETE statements or multiple-table UPDATE statements that act across multiple databases). It is also faster to check only the default database rather than all databases if there is no need.

您还应该了解复制规则。从此处

You should also know the replication rules. From here.

我通过发出 INSERT,DELETE和UPDATE 测试了phpmyadmin,并注意到了(通过启用 general_query_log )发出 INIT DB'db_name' mysql_select_db()记录'Init DB' > API调用。)

I tested phpmyadmin by issuing INSERT, DELETE and UPDATE and noticed(By enabling general_query_log) that it issues INIT DB 'db_name'('Init DB' is logged for the mysql_select_db() API call).

例如:

Init DB sakila
1 Query INSERT INTO `sakila`.`actor_info` (`actor_id`, `first_name`, `last_name`, `film_info`) VALUES ('1235', 'abc', 'efg', NULL)

因此,最终复制应该不会中断,因为phpmyadmin通过在每次查询之前执行USE db来正确执行复制。

So ultimately the replication shouldn't break as phpmyadmin does it correctly by executing USE db before every query.