Mysql2 ::错误:此MySQL版本不允许使用命令:LOAD DATA LOCAL INFILE

前端之家收集整理的这篇文章主要介绍了Mysql2 ::错误:此MySQL版本不允许使用命令:LOAD DATA LOCAL INFILE前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我的完整脚本.

我试图做一个rake任务,从目录中的文件收集数据并将它们加载到mysql中.

我修复了local-infile = 1,没什么用.它只是给我错误

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
最佳答案
这篇文章解决方案对我有用:Enabling local-infile for loading data into remote mysql from rails

将其添加到database.yml

local_infile:true

猜你在找的MySQL相关文章