What am I doing wrong here?
import pymysql, os
directory = os.path.join('path', 'to', 'directory')
filename = 'my_filename.csv'
filepath = os.path.join(directory, filename)
to_table_name = "my_table"
connection = pymysql.connect(..., local_infile=True)
with connection.cursor() as cursor:
load_statement = """
load data local infile %s
into table %s
fields terminated by ','
optionally enclosed by '"'
lines terminated by '\\n'
ignore 1 lines
"""
cursor.execute(load_statement, (filepath, to_table_name, ))
connection.commit()
connection.close
I get the following error message:
ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'my_table\'\n fields terminated by \',\'\n optionally enclosed by \'"\'\n lines\' at line 2')
I want to load my file into a mysql database.
I've tried cursor.execute(load_statement % (filepath, to_table_name))
but to no avail...any help would be much appreciated.