From 01a887efada79e0eca3ca3a83f537a64e9dc9e6b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sun, 12 Nov 2023 13:12:58 +0800 Subject: [PATCH] sync_binlog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 默认,sync_binlog=0,表示MySQL不控制binlog的刷新,由文件系统自己控制它的缓存的刷新。这时候的性能是最好的,但是风险也是最大的。因为一旦系统Crash,在binlog_cache中的所有binlog信息都会被丢失。 如果sync_binlog>0,表示每sync_binlog次事务提交,MySQL调用文件系统的刷新操作将缓存刷下去。最安全的就是sync_binlog=1了,表示每次事务提交,MySQL都会把binlog刷下去,是最安全但是性能损耗最大的设置。这样的话,在数据库所在的主机操作系统损坏或者突然掉电的情况下,系统才有可能丢失1个事务的数据。但是binlog虽然是顺序IO,但是设置sync_binlog=1,多个事务同时提交,同样很大的影响MySQL和IO性能。虽然可以通过group commit的补丁缓解,但是刷新的频率过高对IO的影响也非常大。对于高并发事务的系统来说,“sync_binlog”设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多 --- plugins/mysql/conf/my5.5.cnf | 2 ++ plugins/mysql/conf/my5.6.cnf | 2 ++ plugins/mysql/conf/my5.7.cnf | 3 +++ plugins/mysql/conf/my8.0.cnf | 2 ++ 4 files changed, 9 insertions(+) diff --git a/plugins/mysql/conf/my5.5.cnf b/plugins/mysql/conf/my5.5.cnf index 24a6023c3..70b5c1c66 100644 --- a/plugins/mysql/conf/my5.5.cnf +++ b/plugins/mysql/conf/my5.5.cnf @@ -59,6 +59,8 @@ relay-log=mdserver relay-log-index=mdserver #master +#sync_binlog=1 + #binlog-do-db binlog-ignore-db = test binlog-ignore-db = mysql diff --git a/plugins/mysql/conf/my5.6.cnf b/plugins/mysql/conf/my5.6.cnf index fb8c8c171..35a9c3a7e 100644 --- a/plugins/mysql/conf/my5.6.cnf +++ b/plugins/mysql/conf/my5.6.cnf @@ -62,6 +62,8 @@ relay-log=mdserver relay-log-index=mdserver #master +#sync_binlog=1 + #binlog-do-db binlog-ignore-db = test binlog-ignore-db = mysql diff --git a/plugins/mysql/conf/my5.7.cnf b/plugins/mysql/conf/my5.7.cnf index 28bcdfec5..c6f722823 100644 --- a/plugins/mysql/conf/my5.7.cnf +++ b/plugins/mysql/conf/my5.7.cnf @@ -63,6 +63,8 @@ relay-log=mdserver relay-log-index=mdserver #master +#sync_binlog=1 + #binlog-do-db binlog-ignore-db = test binlog-ignore-db = mysql @@ -84,6 +86,7 @@ replicate-ignore-db = test master_info_repository = table relay_log_info_repository = table + innodb_data_home_dir = {$SERVER_APP_PATH}/data innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = {$SERVER_APP_PATH}/data diff --git a/plugins/mysql/conf/my8.0.cnf b/plugins/mysql/conf/my8.0.cnf index ca92ae86c..c0574c3dc 100644 --- a/plugins/mysql/conf/my8.0.cnf +++ b/plugins/mysql/conf/my8.0.cnf @@ -61,6 +61,8 @@ relay-log=mdserver relay-log-index=mdserver #master +#sync_binlog=1 + #binlog-do-db binlog-ignore-db = test binlog-ignore-db = mysql