Python 3.4 code to load a csv file into MySql

You don’t need Python for that. You don’t even need a program for that. MySQL has a statement for reading CSV files.

See: https://dev.mysql.com/doc/refman/5.1/en/load-data.html , from the documentation:

LOAD DATA INFILE can be used to read files obtained from external sources. For
example, many programs can export data in comma-separated values (CSV) format,
such that lines have fields separated by commas and enclosed within double
quotation marks, with an initial line of column names. If the lines in such a
file are terminated by carriage return/newline pairs, the statement shown here
illustrates the field- and line-handling options you would use to load the file:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

If the input values are not necessarily enclosed within quotation marks, use
OPTIONALLY before the ENCLOSED BY keywords.

Apart from that, MySQL also comes with a program called mysqlimport which can do that too.

Leave a Comment