我们以对MySQL进行实际操作的方式,直观的介绍一下binlog的生成,binlog是二进制存储的,下面我们会利用工具查看binlog的文本内容。
- show variables like 'log_bin'
- -> ;
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | log_bin | ON |
- +---------------+-------+
- 1 row in set (0.00 sec)
查看一下binlog的模式(我需要row-base模式):
- show variables like 'binlog_format';
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | binlog_format | ROW |
- +---------------+-------+
- 1 row in set (0.00 sec)
清除现有的binlog
- MySQL> reset master;
- Query OK, 0 rows affected (0.00 sec)创建一张我们做实验的表MySQL> create table tab(
- -> id INT NOT NULL AUTO_INCREMENT,
- -> user VARCHAR(100) NOT NULL,
- -> clicks INT NOT NULL,
- -> PRIMARY KEY (id)
- -> );
- Query OK, 0 rows affected (0.10 sec)
-
- MySQL> show tables;
- +-------------------+
- | Tables_in_Apache Flinkdb |
- +-------------------+
- | tab |
- +-------------------+
- 1 row in set (0.00 sec)
进行DML操作
- MySQL> insert into tab(user, clicks) values ('Mary', 1);
- Query OK, 1 row affected (0.03 sec)
-
- MySQL> insert into tab(user, clicks) values ('Bob', 1);
- Query OK, 1 row affected (0.08 sec)
-
- MySQL> update tab set clicks=2 where user='Mary'
- -> ;
- Query OK, 1 row affected (0.06 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
-
- MySQL> insert into tab(user, clicks) values ('Llz', 1);
- Query OK, 1 row affected (0.08 sec)
-
- MySQL> update tab set clicks=2 where user='Bob';
- Query OK, 1 row affected (0.01 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
-
- MySQL> update tab set clicks=3 where user='Mary';
- Query OK, 1 row affected (0.05 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
-
- MySQL> select * from tab;
- +----+------+--------+
- | id | user | clicks |
- +----+------+--------+
- | 1 | Mary | 3 |
- | 2 | Bob | 2 |
- | 3 | Llz | 1 |
- +----+------+--------+
- 3 rows in set (0.00 sec)
查看正在操作的binlog
- MySQL> show master statusG
- *************************** 1. row ***************************
- File: binlog.000001
- Position: 2547
- Binlog_Do_DB:
- Binlog_Ignore_DB:
- Executed_Gtid_Set:
- 1 row in set (0.00 sec)
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|