Up vote 2 down vote favorite share g+ share fb share tw.
I am looking for a syntax definition, example, sample code, wiki, etc. for executing a LOAD DATA LOCAL INFILE command from python. I believe I can use mysqlimport as well if that is available, so any feedback (and code snippet) on which is the better route, is welcome. A Google search is not turning up much in the way of current info The goal in either case is the same: Automate loading hundreds of files with a known naming convention & date structure, into a single MySQL table.
David python mysql load-data-infile link|improve this question edited Dec 27 '09 at 3:06OMG Ponies95.2k1065138 asked Aug 5 '09 at 8:36David Perron274 60% accept rate.
– dalloliogm Aug 5 '09 at 10:36 I can use anything. Right now, I only have import MySQLdb in the script. – David Perron Aug 5 '09 at 16:12.
Well, using python's MySQLdb, I use this: connection = MySQLdb. Connect(host='**', user='**', passwd='**', db='**') cursor = connection.cursor() query = "LOAD DATA INFILE '/path/to/my/file' INTO TABLE sometable FIELDS TERMINATED BY ';' ENCLOSED BY '\"' ESCAPED BY '\\\\'" cursor. Execute( query ) connection.commit() replacing the host/user/passwd/db as appropriate for your needs.
This is based on the MySQL docs here, The exact LOAD DATA INFILE statement would depend on your specific requirements etc (note the FIELDS TERMINATED BY, ENCLOSED BY, and ESCAPED BY statements will be specific to the type of file you are trying to read in).
You can also get the results for the import by adding the following lines after your query: results = connection.info().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.