MySQL Blackhole: black hole engine

Keywords: MySQL Database network SQL

Check the output of SHOW ENGINES; or SHOW VARIABLES LIKE 'have%'; to see whether the previous mysql version supports this engine.

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)


How to use it?

When creating a table, specify the engine. (select * from emp; no data when viewing)

mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> create table emp (empno numeric(4) not null,ename varchar(10),job varchar(9),mgr numeric(4),hiredate datetime,sal numeric(7, 2),comm numeric(7, 2),deptno numeric(2)) ENGINE = BLACKHOLE;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into emp values (7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, null, 20);
Query OK, 1 row affected (0.00 sec)
mysql> select * from emp;
Empty set (0.00 sec)


When creating a BLACKHOLE table, the server creates a table definition file in the database directory. The file starts with the name of the table and has a. frm extension. There are no other files associated with this table.

[root@jz_130 ~]# cd /var/lib/mysql/test/
[root@jz_130 test]# ll
total 16
-rw-r-----. 1 mysql mysql   65 Dec  3 23:18 db.opt
-rw-r-----. 1 mysql mysql 8780 Dec  3 23:19 emp.frm


From the above example, you can see that tables using the BLACKHOLE storage engine do not store any data, but if mysql enables binary logging, the SQL statements are written to the log (and copied to the slave server).

When MASTER and SLAVE are synchronized, they act as PROXY between MASTER and SLAVE to relieve the pressure of MASTER and reduce the network bandwidth.

It acts as a relief machine between the normal MASTER and SLAVE, which is used to buffer the pressure of the MASTER machine and connect SLAVE to the relief machine, so as to reduce the network transmission between the MASTER and SLAVE. Thus, the bandwidth of the network and the pressure of the host are reduced.

All processing is done by an intermediate agent machine.

Posted by chriswheat on Sat, 30 Nov 2019 05:13:34 -0800