[ mysql ] 錯誤訊息 Unsafe statement written to the binary log
使用 mysql slave 機制時在記錄檔出現
Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
這個意思大致是說在操作資料表時,沒有使用唯一的 key 來做更新(刪除),但使用 Limit 限制可操作的筆數,是有風險的。
例如
現在要刪除一筆資料
DELETE FROM 資料表 WHERE 年齡=10 Limit 1;
可能會刪除其中哪一筆不一定,如此可能發生主從資料庫不同步狀況。
這時同步的方法要做修改
mysql> SET GLOBAL binlog_format = 'ROW';
使用原始資料做記錄,但會較佔用空間。
可以先採用
binlog_format =mixed (statement+row)
來處理。
Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
這個意思大致是說在操作資料表時,沒有使用唯一的 key 來做更新(刪除),但使用 Limit 限制可操作的筆數,是有風險的。
例如
姓名 | 年齡 | 性別 |
小明 | 10 | man |
小華 | 10 | man |
現在要刪除一筆資料
DELETE FROM 資料表 WHERE 年齡=10 Limit 1;
可能會刪除其中哪一筆不一定,如此可能發生主從資料庫不同步狀況。
這時同步的方法要做修改
mysql> SET GLOBAL binlog_format = 'ROW';
使用原始資料做記錄,但會較佔用空間。
可以先採用
binlog_format =mixed (statement+row)
來處理。