Is there a way to import multiple csv files at the same time into a MySQL database? Some sort of batch import?
I'm on Mac OSX running a MAMP server.
I have 185 csv files that I need to import into a MySQL table. I can import them individually using phpMyAdmin's import tab, but it would take a long time. Does anyone know if there is a better way?
@hlosukwakha you want to use
mysqlimport
. this searches for a table named like the file. usemysqlimport -help
to find the correct parameters, but they're basically identical tomysql
You could use a shell script to loop through the files (this one assumes they're in the current directory):
In python you can use d6tstack which makes this simple
It also deals with data schema changes, creates table and allows you to preprocess data.
I've modified Tom's script to solve few issues that faced
load data local infile
instead ofload data infile
: [file to be loaded was local to mysql server]--local-infile
to enabled local data load mode on client.For windows User use this batch
d
for drive letter,p
for path to file,n
for filename,x
for extension and f is file variableSteps: - Put that batch file in directory where all multiple csv files exist and named it as something.bat - run cmd.exe as adminstrator and call that something.bat file and enjoy importing...
Use a shell script like this: