Large MySQL table, inserts with primary key check
I think what you're looking is simply to use INSERT IGNORE. Forget about steps 1 and 2, just insert and ignore :)


  If you use the IGNORE keyword, errors that occur while executing the INSERT statement are ignored. For example, 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 is discarded and no error occurs. Ignored errors may generate warnings instead, although duplicate-key errors do not.