binlog_format设置为statement时,从机采用与主机执行同样语句的方式同步。
这时不同的函数就会有不同的影响
双机A机:
mysql> set binlog_format=statement;
Query OK, 0 rows affected (0.00 sec)
mysql> update test set d = now() where id =1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 04:55:57 |
+----+---------------------+
1 row in set (0.00 sec)
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2015-03-10 04:56:17 |
+---------------------+
1 row in set (0.00 sec)
双主B机
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 04:55:57 |
+----+---------------------+
1 row in set (0.00 sec)
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2015-03-10 09:19:14 |
+---------------------+
1 row in set (0.00 sec)
此时AB数据一样。
改用sysdate()
A机
mysql> update test set d = sysdate() where id =1;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 04:56:34 |
+----+---------------------+
1 row in set (0.00 sec)
B机
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 09:19:24 |
+----+---------------------+
1 row in set (0.00 sec)
可以看到B机更新成了本地时间,这时数据不一致了。
因此一般为了数据一致会把参数设成row
两台机子都设置如下
mysql> set binlog_format=row;
Query OK, 0 rows affected (0.00 sec)
A机
mysql> update test set d = sysdate() where id =1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 05:02:44 |
+----+---------------------+
1 row in set (0.00 sec)
B机
mysql> select * from test;
+----+---------------------+
| id | d |
+----+---------------------+
| 1 | 2015-03-10 05:02:44 |
+----+---------------------+
1 row in set (0.00 sec)
可以看到这时结果一致了