2

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()

1 Answer 1

2

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';'''
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.