【发布时间】:2022-01-02 17:17:29
【问题描述】:
在将更改写入 innodb 存储引擎中的二进制日志时,我试图了解这 3 个变量
innodb_flush_log_at_trx_commit
在这里阅读了几次文档后,我对这些变量的理解是什么
sync_binlog
0 -> Operating system decides when to write log to disk(whenever it has free time)
1 -> after every commit changes written to disk(safest)
N -> after N commits changes written to disk
innodb_flush_log_at_trx_commit
0 -> written and flushed to disk once per second
1 -> written and flushed after every commit(safest)
2 -> written after every commit and flushed to disk once per second
innodb_flush_log_at_timeout
after N seconds of delay logs are written to file
所以作为一个实验,这是我想要实现的目标
1)在提交 5 个事务之前,不应将任何事务写入日志
2) 提交 5 个事务后,我希望 innodb 等待 10 秒,然后将这些事务写入日志
所以我将变量设置如下
SET @@GLOBAL.sync_binlog=5; #Don't write anything until 5 commits have been done?
SET @@GLOBAL.innodb_flush_log_at_trx_commit=0; #Maybe? because logs are written every second regardless if they are commited or not?
SET @@GLOBAL.innodb_flush_log_at_timeout=10; #After 5 commit's wait for 10 seconds before writing the transaction's to disk?
如您所见,我到处都放了问号,因为我不知道自己在做什么。 而且这些设置不起作用。每次提交后,我都会立即在日志中看到更改更新
基本上我有一个测试表
CREATE TABLE Test(TestCol INT);
我将 5 个事务的[auto commit is on] 作为 5 个插入语句发出
INSERT INTO Test VALUES(1);
INSERT INTO Test VALUES(2);
INSERT INTO Test VALUES(3);
INSERT INTO Test VALUES(4);
INSERT INTO Test VALUES(5);
我想要的是,如果我插入值让我们说只有 1 到 4,那么我不想看到日志文件中的任何更改,但是一旦我插入 5 以及总共 5 个事务然后我想要让 innodb 在将这些事务写入日志之前等待 10 秒,这样我就有足够的时间打开 我的文件资源管理器并运行
mysqlbinlog --verbose --base64-output=DECODE-ROWS binlog.000001
查看我的日志文件中的更改
但即使我只插入一个值并打开我的日志文件,我也会立即看到该插入。
我的目标甚至可能吗?有人能解释一下这些变量是如何工作的吗?如果可能的话,还有一个替代解决方案可以解决我的问题吗?
任何澄清将不胜感激
【问题讨论】:
标签: mysql transactions innodb mysqlbinlog