我正在测试insert-select查询并注意到一个奇怪的结果.
CREATE TABLE `test` (
`cnt` int(11) NOT NULL AUTO_INCREMENT,
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
PRIMARY KEY (`cnt`)
)
CREATE TABLE `test_current` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
)
Run Code Online (Sandbox Code Playgroud)
首先,我创建了两个表,并在test_current中插入一些值
mysql> insert into test_current (a,b) values (1,1),(2,2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
Run Code Online (Sandbox Code Playgroud)
我做了这个查询
mysql> INSERT INTO test (a,b) SELECT a,b FROM test_current;
Query OK, 2 rows affected, 1 warning (0.00 sec)
Records: 2 Duplicates: 0 Warnings: …Run Code Online (Sandbox Code Playgroud) 我使用log-error将警告/错误写入文件.当我执行INSERT IGNORE..SELECT语句时,它只是继续写这个警告消息.
120905 3:01:23 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT IGNORE... SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are ignored. This order cannot be predicted and may differ on master and the slave.
Run Code Online (Sandbox Code Playgroud)
我想停止mysql logwriter一遍又一遍地写上面的错误.(我看不到其他日志,因为他们填写了整个日志文件......)
首先,我将(a,b,c)插入表中.c在表格中应该是唯一的,并且a,b用于选择.查询将是这样的
SELECT c FROM table WHERE a=value1 AND value2<b AND b<value3
Run Code Online (Sandbox Code Playgroud)
我的插入查询是
INSERT IGNORE INTO table VALUES (,,),(,,)...(,,)
Run Code Online (Sandbox Code Playgroud)
我以为我可以更改查询而不是产生警告,但我的数据包含唯一字段,我需要保证该字段在表中是唯一的.每隔几秒钟应该插入500~2000行,所以我需要进行批量插入.
如果已经插入了数十亿行,我需要在几秒钟内插入另外2000行.如何在不填写带警告的日志文件的情况下将它们安全地插入到表中?
(我无法关闭二进制日志,因为我需要使用mysql复制.)