|
原帖由 ban_ping 于 2011-5-20 11:22 发表 ![]()
innodb,没有提交不可能有数据的。
另外,二进制日志是先写buffer再写磁盘的,buffer大小由binlog_cache_size决定。
sync_binlog参数会控制二进制日志的写入磁盘,默认为0.
如果设置为1,则写入buffer后会马上同步写入磁盘,这时候事务有可能还未提交。
但是在Innodb下我怎么测试都是只有提交完才会写二进制日志,不提交的话二进制日志是不会写入的,而不是缓存写入磁盘的关系。
mysql> show create table T2;
+-------+------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------+
| T2 | CREATE TABLE `T2` (
`id` int(11) DEFAULT NULL,
`name` char(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set GLOBAL sync_binlog=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1057 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> insert into T2 values (1,1);
Query OK, 1 row affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1057 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1247 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> set GLOBAL sync_binlog=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1247 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> insert into T2 values (1,1);
Query OK, 1 row affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1247 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000067 | 1437 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec) |
|