Skip to content

Instantly share code, notes, and snippets.

@Peter-Hudson
Last active September 30, 2015 11:19
Show Gist options
  • Save Peter-Hudson/93212e98ebb4d5dc223c to your computer and use it in GitHub Desktop.
Save Peter-Hudson/93212e98ebb4d5dc223c to your computer and use it in GitHub Desktop.
Testing the import of a CSV file into MySQL

mysql -utest -p test --local-infile

CREATE TEMPORARY TABLE IF NOT EXISTS `tempy` (
    `tempy_id` INT(21) AUTO_INCREMENT,
    `tempy_value` INT(21) DEFAULT NULL,
    PRIMARY KEY (`tempy_id`)
)ENGINE = InnoDB;

LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE `tempy`
	FIELDS TERMINATED BY ',' ENCLOSED BY '"'
	LINES TERMINATED BY '\r\n'
	IGNORE 1 LINES 
	(`tempy_value`)
;

SELECT * FROM `tempy`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment