How to insert a space delimited text file into mysql using Python? [closed]

You need to set the delimiter to csv.reader function:

csvreader = csv.reader(textfile, delimiter="\t")

You didn’t do it in your code, so Python doesn’t split the line of your CSV file. That’s why it gives the error.


If you have the file with all the columns of MySQL table, you can use LOAD DATA INFILE
command. It’s much faster, then loading line by line.

LOAD DATA INFILE 'externaldatabase.txt'
INTO TABLE database_name.externaldatabase
FIELDS TERMINATED BY '\t';

Leave a Comment