Python2.7 MySQL Connector Error on LOAD DATA LOCAL INFILE

后端 未结 4 791
我寻月下人不归
我寻月下人不归 2021-01-14 08:26

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

4条回答
  •  無奈伤痛
    2021-01-14 08:35

    Okay, here's what I've figured out.

    @Dd_tch - your answer helped me realize that this code would work better:

    query = add_csv_file % csv_info
    cursor.execute(query)
    

    Though the MySQL site for Connector seems to indicate you could do what I was doing (http://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html), that wasn't working.

    When I fixed that, I got a new error: mysql.connector.errors.ProgrammingError: 1148 (42000): The used command is not allowed with this MySQL version

    There are several sites that indicate that this could be fixed by adding "local_infile=1" to the MySQL Connector config. Here's one: http://dev.mysql.com/doc/refman/5.1/en/loading-tables.html

    This solution did not work for me. My local_infile is set to 1 on MySQL and I can't set it within the Python code or I get an e

    I'm going to instead replace the LOAD LOCAL DATA INFILE with something that will read CSV files line by line and insert lines into the database. This will make the code more portable to other DBs anyway.

提交回复
热议问题