Created
January 22, 2013 07:19
-
-
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 …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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