ふとした事から、レプリケーション周りの調査をしているところ。
MySQL4.1.1から、特定のDBやテーブルのみをレプリケーション対象とする事ができる様になったらしい事を知りました。
MySQL :: MySQL 4.1 リファレンスマニュアル :: 4.11.6 レプリケーションスタートアップオプション
`SHOW SLAVE STATUS \G`で、'Replicate_%'な項目が確認できますが、これらがそのオプションで指定されているものです。が、これらをどうやって指定するのか、微妙にわかりません。
webのマニュアルを見る限り、mysqldの起動オプションで指定すればよいような印象ですが、どうなんでしょう。
# Replicate_Do_Table, Replicate_Ignore_Table, Replicate_Wild_Do_Table, Replicate_Wild_Ignore_Table
--replicate-do-table、--replicate-ignore-table、--replicate-wild-do-table、--replicate-wild-ignore_table の各オプションでテーブルが指定されていれば、その一覧。
これらのフィールドは、MySQL 4.1.1 で導入された。
MySQL :: MySQL 4.1 リファレンスマニュアル :: 4.11.6 レプリケーションスタートアップオプション
`man mysqld`で`mysqld --verbose --help`したら何かが見れる事を知ったので、その中から'--replicate-*'なものを抽出してみました。
--replicate-do-db=name
Tells the slave thread to restrict replication to the
specified database. To specify more than one database,
use the directive multiple times, once for each database.
Note that this will only work if you do not use
cross-database queries such as UPDATE some_db.some_table
SET foo='bar' while having selected a different or no
database. If you need cross database updates to work,
make sure you have 3.23.28 or later, and use
replicate-wild-do-table=db_name.%.
--replicate-do-table=name
Tells the slave thread to restrict replication to the
specified table. To specify more than one table, use the
directive multiple times, once for each table. This will
work for cross-database updates, in contrast to
replicate-do-db.
--replicate-ignore-db=name
Tells the slave thread to not replicate to the specified
database. To specify more than one database to ignore,
use the directive multiple times, once for each database.
This option will not work if you use cross database
updates. If you need cross database updates to work, make
sure you have 3.23.28 or later, and use
replicate-wild-ignore-table=db_name.%.
--replicate-ignore-table=name
Tells the slave thread to not replicate to the specified
table. To specify more than one table to ignore, use the
directive multiple times, once for each table. This will
work for cross-datbase updates, in contrast to
replicate-ignore-db.
--replicate-rewrite-db=name
Updates to a database with a different name than the
original. Example:
replicate-rewrite-db=master_db_name->slave_db_name.
--replicate-same-server-id
In replication, if set to 1, do not skip events having
our server id. Default value is 0 (to break infinite
loops in circular replication). Can't be set to 1 if
--log-slave-updates is used.
--replicate-wild-do-table=name
Tells the slave thread to restrict replication to the
tables that match the specified wildcard pattern. To
specify more than one table, use the directive multiple
times, once for each table. This will work for
cross-database updates. Example:
replicate-wild-do-table=foo%.bar% will replicate only
updates to tables in all databases that start with foo
and whose table names start with bar.
--replicate-wild-ignore-table=name
Tells the slave thread to not replicate to the tables
that match the given wildcard pattern. To specify more
than one table to ignore, use the directive multiple
times, once for each table. This will work for
cross-database updates. Example:
replicate-wild-ignore-table=foo%.bar% will not do updates
to tables in databases that start with foo and whose
table names start with bar.
mysqld実行時に渡せるオプションは、my.cnfに記述できるんでしたっけ。頭のハイフン削ったものが設定値の名前だった気がしないでもないですが、覚えていません。
試してみればすぐわかる事ではありますが、全く知らないオプションの存在をしったので、勢いでメモです。Railsみたく、複数環境で多数のDBを使う場合、productionのものだけをレプリケーション対象とした方がいいのでしょうかね。障害でスレーブがマスタになったとき、本番用のproduction環境以外のDBが存在しないか空だったとしても、何も困らないですね。即座にテストが実行できない問題はありますが、たいした事でもない様に思います。
'--replicate-wild-do-table=%_production.%'あたりでしょうかね。
'--binlog-do-db=db_name'か'--binlog-ignore-db=db_name'を使って、そもそも、バイナリログに書き出さない方法もありか。

