Reputation: 57
I get this error:
SyntaxError: EOL while scanning string literal
while trying to push a CSV file of more than 20 million rows to MySQL server, using this python code:
cur = connection.cursor()
query = "LOAD DATA LOCAL INFILE 'path to csv file' INTO TABLE table.name FIELDS OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n';"
cur.execute( query )
connection.commit()
Upvotes: 2
Views: 381
Reputation: 106975
When you enclose a string literal with a double quote in double quotes, you should either escape the double quote with a back slash:
query = "LOAD DATA LOCAL INFILE 'path to csv file' INTO TABLE table.name FIELDS OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n';"
or enclose the string literal in triple quotes:
query = '''LOAD DATA LOCAL INFILE 'path to csv file' INTO TABLE table.name FIELDS OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n';'''
Upvotes: 2