I\'m trying to dynamically load census data into a mysql database (from .csv files) using Python and MySQL Connector.
I can\'t figure out why I am getting the error
This is easily solved with adding the appropriate client flag in your connection as below:
import mysql.connector
from mysql.connector.constants import ClientFlag
cnx = mysql.connector.connect(user='[username]', password='[pass]', host='[host]', client_flags=[ClientFlag.LOCAL_FILES])
cursor = cnx.cursor()
This will give permission for MySQL to access the local files on your machine and then the following LOAD will work:
LoadSQL = """LOAD DATA LOCAL INFILE '%s'
INTO TABLE %s
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(field1, field2, field3, field4)""" % (csvfile, tabl_name)
cursor.execute(LoadSQL)
cnx.commit()
cursor.close()
cnx.close()