在做主從複製下,插入資料的時候出現下面的錯誤提示:
| 代碼如下 |
複製代碼 |
mysql> insert into test values (”,’lzh’); ERROR 1598 (HY000): Binary logging not possible. Message: Transaction level ‘READ-COMMITTED’ in InnoDB is not safe for binlog mode ‘STATEMENT’ |
查看一下,是否是:
| 代碼如下 |
複製代碼 |
mysql> show global variables like ‘binlog_format%'; +—————+——-+ | Variable_name | Value | +—————+——-+ | binlog_format | STATEMENT | +—————+——-+ 1 row in set (0.00 sec) |
中文意思是,二進位日誌不可用,因為,在innodb引擎下的READ-COMMITTED這種事務類別下,二進位的模式為STATEMENT,會不安全,查資料瞭解到
SQL標準定義了4類隔離等級:
Read Uncommitted(讀取未提交內容)
Read Committed(讀取提交內容
Repeatable Read(可重讀)
Serializable(可序列化)
而binlog模式分三種(row,statement,mixed)
解決方案:
方法一:臨時生效,重啟失效(實際點的生產環境下,可能不允許重啟資料庫,這時,需要用這個方法)
| 代碼如下 |
複製代碼 |
mysql> set global binlog_format=row; Query OK, 0 rows affected (0.00 sec) mysql> show global variables like ‘binlog_format%'; +—————+——-+ | Variable_name | Value | +—————+——-+ | binlog_format | ROW | +—————+——-+ |
方法二:修改設定檔,永久生效
| 代碼如下 |
複製代碼 |
[root@localhost ~]# grep -E “innodb_locks_unsafe_for_binlog|binlog_format = ROW” /data/3306/my.cnf binlog_format = ROW innodb_locks_unsafe_for_binlog = 1 |
重啟MySQL,在插入資料,試試
| 代碼如下 |
複製代碼 |
mysql> insert into test values (”,’lzh’); ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect… Connection id: 1 Current database: test Query OK, 1 row affected, 1 warning (0.00 sec) |
總結:一般,二種方法同時用,效果最佳