Skip to content

Instantly share code, notes, and snippets.

@lgaa
Forked from kbsali/mysql-innodb-bulk-inserts.sql
Created August 23, 2017 15:09
Show Gist options
  • Save lgaa/f73f8982ccd5f87bc8e40c09a53cc64b to your computer and use it in GitHub Desktop.
Save lgaa/f73f8982ccd5f87bc8e40c09a53cc64b 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;
@lgaa
Copy link
Author

lgaa commented Aug 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment