mysql 不支持load data_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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值