MySQL:BlackHole
MySQL:BlackHole
顾名思义BlackHole就是黑洞,只有写入没有输出.现在就来实验一下吧
首先查看一下MySQL支持的存储引擎
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
创建一个BlackHole类型的表
mysql> create table test(id int, name char(10)) engine=blackhole ;
Query OK, 0 rows affected (0.02 sec)
mysql> desc test
-> ;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> alter table test add primary key (id);
Query OK, 0 rows affected (0.50 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc test;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) NOT NULL DEFAULT '0',
`name` char(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> insert into test values(1,'ni') ;
Query OK, 1 row affected (0.03 sec)
mysql> insert into test values(2,'wo') ;
Query OK, 1 row affected (0.01 sec)
mysql> insert into test values(3,'ta') ;
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
Empty set (0.00 sec)
mysql> system ls /mysql/data/test
db.opt test.frm test.ibd
mysql> exit
从上面的例子中可以看出使用BLACKHOLE存储引擎的表不存储任何数据,如果mysql启用了二进制日志,SQL语句被写入日志(并被复制到从服务器)。这样使用BLACKHOLE存储引擎的mysqld可以作为主从复制中的中转站或在其上面添加过滤器机制。例如,假设你的应用需要从服务器侧的过滤规则,但传输所有二进制日志数据到从服务器会导致较大的网络流量。在这种情况下,在主服务器主机上建立一个伪从服务器进程。
主服务器的操作写入二进制日志,伪mysqld进程作为从服务器,在伪mysqld进程上配置replicate-do和replicate-ignore规则,并且写一个新的,被过滤的二进制日志 。这个已过滤日志被提供给其他真正的从服务器。因为伪进程不存储任何数据,只消耗很小的额外的mysqld进程资源。这个类型的建立可以用额外复制从服务器来重复。
当然如果配置一主多从的话,多个从服务器会在主服务器上分别开启自己相对应的线程,执行binlog dump命令而且多个此类进程并不是共享的。为了避免因多个从服务器同时请求同样的事件而导致主机资源耗尽,可以单独建立一个伪的从服务器或者叫分发服务器:
其它可能对BLACKHOLE存储引擎的使用包括:
1 转储文件语法的验证。
2 来自二进制日志记录的开销测量,通过比较允许二进制日志功能的BLACKHOLE的性能与禁止二进制日志功能的BLACKHOLE的性能。
3 因为BLACKHOLE本质上是一个“no-op” 存储引擎,它可能被用来查找与存储引擎自身不相关的性能瓶颈。
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.
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.
参考:
http://control.blog.chinaunix.net/uid-10661836-id-4033704.html
http://dev.mysql.com/doc/refman/5.5/en/blackhole-storage-engine.html
posted on 2014-04-02 23:15 Still water run deep 阅读(412) 评论(0) 编辑 收藏 举报