Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This is my full script.

Am trying to make a rake task which collects data from the files in the directory and loads them in the mysql.

I fixed the local-infile = 1, Nothing works. It just gives me the 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
like image 897
Ashwin Yaprala Avatar asked Jan 30 '13 09:01

Ashwin Yaprala


1 Answers

The solution from this post worked for me : Enabling local-infile for loading data into remote mysql from rails

add this to database.yml

local_infile: true

like image 151
Paul Y Avatar answered Sep 28 '22 01:09

Paul Y