mysql的sync_binlog参数实验
mysql sync_binlog参数实验
1,默认参数为1,即每次提交MySQL将进行一次fsync之类的磁盘同步指令来将binlog_cache中的数据强制写入磁盘
mysql> show variables like '%sync_binlog%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sync_binlog | 1 |
+---------------+-------+
1 row in set (0.01 sec)
mysql>
mysql>
2,实验环境搭建
清除测试表t
mysql> truncate t;
Query OK, 0 rows affected (0.02 sec)
mysql>
创建一个存储过程p1,往t表中进行五千次的插入,每次插入都提交
mysql> DELIMITER //
mysql> CREATE PROCEDURE p1()
-> begin
-> declare i int;
-> set i=0;
-> while i<5000 do
-> insert into t values(i);
-> set i=i+1;
-> commit;
-> end while;
-> end;
-> //
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
3,当sync_binlog=1时,p1执行14.04秒
mysql>
mysql> call p1;
Query OK, 0 rows affected (14.04 sec)
mysql>
mysql>
4,当sync_binlog=0时,p1执行6.94秒
mysql> set global sync_binlog=0;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> truncate t;
Query OK, 0 rows affected (0.02 sec)
mysql> call p1;
Query OK, 0 rows affected (6.94 sec)
5,当sync_binlog=5时,p1执行8.28秒
mysql> set global sync_binlog=5;
Query OK, 0 rows affected (0.00 sec)
mysql> truncate t;
Query OK, 0 rows affected (0.02 sec)
mysql> call p1;
Query OK, 0 rows affected (8.28 sec)
mysql>
正文到此结束