Skip to content

Instantly share code, notes, and snippets.

@hamidreza-s
Created January 22, 2013 07:19
Show Gist options
  • Save hamidreza-s/4592754 to your computer and use it in GitHub Desktop.
Save hamidreza-s/4592754 to your computer and use it in GitHub Desktop.
Instead of writing a script to pull in information from a CSV file, you can link MYSQL directly to it and upload the information using the following SQL syntax. To import an Excel file into MySQL, first export it as a CSV file. Remove the CSV headers from the generated CSV file along with empty data that Excel may have put at the end of the CSV …
# Create Table
CREATE TABLE IF NOT EXISTS `foo_table` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`bar_column` varchar(10) NOT NULL,
`bat_column` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# Load Data
load data local infile '/path/to/file.csv' into table `foo_table`
fields
terminated by ','
enclosed by '"'
lines terminated by '\n'
(`bar_column`, `bat_column`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment