Create a composite unique index. This will allow any number of duplicates in the individual fields, but the combination needs to be unique.
CREATE UNIQUE INDEX ix_uq ON test (field1, field2, field3);
...and use INSERT IGNORE
to insert if the unique index is not violated. If it is, just ignore the insert.
INSERT IGNORE INTO test (field1,field2,field3) VALUES (1,1,1);
If you want to insert unless there's a duplicate, and update if there is, you can also use INSERT INTO ... ON DUPLICATE KEY UPDATE
;
INSERT INTO test (field1, field2, field3) VALUES (1,1,1)
ON DUPLICATE KEY UPDATE field4=field4+1;