LOCK TABLES `table_name` WRITE;
SET autocommit=0;
SET foreign_key_checks=0;
SET unique_checks=0;


/*....
INSERT ... ON DUPLICATE KEY UPDATE
INSERT IGNORE INTO 
....*/


SET unique_checks=1;
SET foreign_key_checks=1;
COMMIT;
SET autocommit=1;
UNLOCK TABLES;