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)
可以看到這時結果一致了