From my understanding INSERT IGNORE inserts a new entry if it doesn't already exists, if it does, ignore it. So I've been trying to do that for a while and it doesn't seem to be working. Here's my attempt:
insert insert ignore into rss_feeds (md5sum) values ("1234");
Query OK, 1 row affected (0.00 sec)
mysql> insert ignore into rss_feeds (md5sum) values ("1234");
Query OK, 1 row affected (0.00 sec)
mysql> insert ignore into rss_feeds (md5sum) values ("1234");
Query OK, 1 row affected (0.00 sec)
mysql> insert ignore into rss_feeds (md5sum) values ("1234");
Query OK, 1 row affected (0.00 sec)
mysql> select * from rss_feeds where md5sum="1234";
+------+--------+----------+---------+----------+--------+--------+---------+
| link | source | headline | updated | inserted | md5sum | itemid | emailed |
+------+--------+----------+---------+----------+--------+--------+---------+
| NULL | NULL | NULL | NULL | NULL | 1234 | NULL | NULL |
| NULL | NULL | NULL | NULL | NULL | 1234 | NULL | NULL |
| NULL | NULL | NULL | NULL | NULL | 1234 | NULL | NULL |
| NULL | NULL | NULL | NULL | NULL | 1234 | NULL | NULL |
+------+--------+----------+---------+----------+--------+--------+---------+
4 rows in set (0.00 sec)
解决方案
As documented under INSERT Syntax:
without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.
You need to define a UNIQUE index on md5sum:
ALTER TABLE rss_feeds ADD UNIQUE INDEX (md5sum);