Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL LOAD DATA LOCAL INFILE Python

Tags:

I am running Ubuntu 12.04 and MySQL 5.5 Alright so here is the problem:

Using the MySQLDB module for Python, the SQL command:

cursor.execute("LOAD DATA LOCAL INFILE 'example.csv' INTO TABLE 'example_mysql_table' TERMINATED BY ',';") 

Doesn't work. I get ERROR 1148: The used command is not allowed with this MySQL version

I have looked around for a solution for this for a while now, and so far it seems other people having the same problem have fixed it by adding "local-infile = 1" to 'my.cnf' underneath [mysqld] and [mysql]. This has not worked for me, and I am not sure why.

Relevant Link:

MySQL: Enable LOAD DATA LOCAL INFILE

like image 421
user1746082 Avatar asked Oct 15 '12 06:10

user1746082


1 Answers

After spending hours on trying all kinds of settings in the config files and restarting mysql dozens of times I came up with this which seems to solve the problem (could not find this in any documentation anywhere)

MySQLdb.connect(server, username, password, database, local_infile = 1) 
like image 157
Johann Bosman Avatar answered Jan 04 '23 01:01

Johann Bosman