Skip to content

Instantly share code, notes, and snippets.

@kbsali
Last active August 23, 2017 15:09
Show Gist options
  • Save kbsali/7597954 to your computer and use it in GitHub Desktop.
Save kbsali/7597954 to your computer and use it in GitHub Desktop.
Mysql InnoDB + MyIsam bulk insert statements
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;
LOCK TABLES `table_name` WRITE;
/*!40000 ALTER TABLE `table_name` DISABLE KEYS */;
/*....
INSERT INTO ... ON DUPLICATE KEY UPDATE
INSERT IGNORE INTO
....*/
/*!40000 ALTER TABLE `table_name` ENABLE KEYS */;
UNLOCK TABLES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment