Mysql2 :: Error: The command used is not allowed with this version of MySQL: LOAD DATA LOCAL INFILE

This is my full script.

I am trying to do a rake task that collects data from files in a directory and uploads it to mysql.

I set local-infile = 1, nothing works. It just gives me an error

namespace :db do namespace :load do desc "Load Properties into DB" task :properties => :environment do Mysql2::Client.default_query_options[:connect_flags] |= Mysql2::Client::LOCAL_FILES @files = Dir.entries("db/property_website_scripts/") connection = ActiveRecord::Base.connection() for file in @files next if file == "." || file == ".." sql = "LOAD DATA LOCAL INFILE '#{Rails.root}/db/property_website_scripts/#{file}' INTO TABLE properties FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' (property_type,property_for,city,state,country......);" connection.execute(sql) end #updating created at and updated at Property.update_all({:created_at => Time.now, :updated_at => Time.now}, "created_at IS NULL") end end end 
+4
source share
2 answers

The solution from this post worked for me: Enabling local access to load data into remote mysql from rails

add this to database.yml

local_infile: true

+2
source

I get the same error with version 0.3.11 from the mysql2 . Since I used this version for a while, I assume this is some kind of dependency problem with another stone. Try updating version 0.3.12b5 , which fixed it for me.

0
source

All Articles