the blackhole storage engine acts as a “black hole” that accepts data but throws it away and does not store it. retrievals always return an empty result:
和其 blackhole 名字的含義一樣,該存儲引擎會将所有接收到的資料”吞沒“,在本地不會儲存所接收到的資料。是以當然也無法從對應的表中回去到相應的結果集。
<a href="http://my.oschina.net/moooofly/blog/158869#">?</a>
1
2
3
4
5
6
7
8
9
<code>mysql></code><code>create</code> <code>table</code> <code>test(i</code><code>int</code><code>, c</code><code>char</code><code>(10)) engine = blackhole;</code>
<code>query ok, 0</code><code>rows</code> <code>affected (0.03 sec)</code>
<code>mysql></code><code>insert</code> <code>into</code> <code>test</code><code>values</code><code>(1,</code><code>'record one'</code><code>),(2,</code><code>'record two'</code><code>);</code>
<code>query ok, 2</code><code>rows</code> <code>affected (0.00 sec)</code>
<code>records: 2 duplicates: 0 warnings: 0</code>
<code>mysql></code><code>select</code> <code>*</code><code>from</code> <code>test;</code>
<code>empty</code><code>set</code> <code>(0.00 sec)</code>
編譯階段使能 blackhole 存儲引擎。
to examine the source for the blackhole engine, look in the sql directory of a mysql source distribution.
源檔案檢視。
when you create a blackhole table, the server creates a table format file in the database directory. the file begins with the table name and has an .frm extension. there are no other files associated with the table.
建立 blackhole 表會産生相應的表格式檔案:.frm。并且僅會産生該檔案。
the blackhole storage engine supports all kinds of indexes. that is, you can include index declarations in the table definition.
blackhole 存儲引擎吃吃各種類型索引。
通過mysql指令行檢視是否可以使用 blackhole 存儲引擎建立表。
inserts into a blackhole table do not store any data, but if statement based binary logging is enabled, the sql statements are logged and replicated to slave servers. this can be useful as a repeater or filter mechanism.
向 blackhole 表中 insert 資料時,實際不會存儲到表中,但在使能了基于語句的 binlog 時,會記錄下 sql 語句,并可用于 slave 複制。這也就是 blackhole 會被用作複制結構中 中繼器 或 過濾機制 的原因。
note
when using the row based format for the binary log, updates and deletes are skipped, and neither logged nor applied. for this reason, you should use statement for the binary logging format, and not row or mixed.
注意:在使用基于行的 binlog 時,update 和 delete 會被忽略,既不會被記錄到log中也不會被真正執行。基于這個原因,應該使用基于語句的 binlog 而不是基于行或者混合模式的 binlog 。
suppose that your application requires slave-side filtering rules, but transferring all binary log data to the slave first results in too much traffic. in such a case, it is possible to set up on the master host a “dummy” slave process whose default storage engine is blackhole, depicted as follows:
在考慮 slave 側需要過濾功能的應用場景時,如果将完整 binlog 傳輸到 slave 的代價是非常大的,則可以在 master 伺服器上建立一個 使用 blackehole 存儲引擎的 ”dummy“ slave 程序,如下圖:
master 會寫自己的 binlog 檔案,而”dummy“ mysqld 程序扮演了 slave 的角色,根據配置的 replicate-do-* 和 replicate-ignore-* 規則,記錄被自身過濾後的 binlog 日志。而這個 binlog 日志就可以作為其他真正 slave 進行複制的源。
由于 dummy 程序實際上沒有存儲任何資料,是以幾乎不會為 master 主機帶來額外開銷。
other possible uses for the blackhole storage engine include:
verification of dump file syntax.
measurement of the overhead from binary logging, by comparing performance using blackhole with and without binary logging enabled.
blackhole is essentially a “no-op” storage engine, so it could be used for finding performance bottlenecks not related to the storage engine itself.
blackhole 的其他可能用途:
校驗轉儲檔案文法。
測量開啟 binlog 日志所帶來的額外開銷。
查找和存儲引擎無關的其他方面的性能瓶頸。
the blackhole engine is transaction-aware, in the sense that committed transactions are written to the binary log and rolled-back transactions are not.