1. 查看 binlog_format
show variables like 'binlog_format';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
2. 特征
在二进制文件中直接记录原始 SQL,且为明文。
比如,执行这样一条语句:
insert into test_replication(name, file) values('name01', load_file('/var/lib/mysql/pic.jpg'));
甚至会有警告:
show warnings;
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Note | 1592 | Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
警告:在模式 statement 情况,使用了系统函数,可能会在 slave 上返回不同的值,这是不安全的。
ps:由于笔者正在启用主从复制,因此会有这样的提示。
于是,查看 binlog,发现:
#191205 11:29:15 server id 1000 end_log_pos 547 CRC32 0xecd266c1 Query thread_id=8 exec_time=0 error_code=0
use `replication`/*!*/;
SET TIMESTAMP=1575516555/*!*/;
insert into test_replication(name, file) values('name01', load_file('/var/lib/mysql/pic.jpg'))
/*!*/;
# at 547
#191205 11:29:15 server id 1000 end_log_pos 578 CRC32 0xac1005f4 Xid = 33
COMMIT/*!*/;
的确,一模一样地抄写了 SQL 。