问题:MYSQL和RUBY(不带rails?)会出错:
此MySQL版本(Mysql :: Error)
不允许使用used命令亲爱的朋友们,
我可以从命令行发出这个,但不是来自我的ruby(没有rails)。
的MySQL>将数据本地infile'remediation_rewrite.csv'加载到表report.remediation IGNORE 1行(MACHINE_NAME,TYPE_OF_ACTION,SCORE,FILE_PATH,MD5,REGKEY,VThit,action,action_result,action_result_detail,date); 查询正常,455168行受影响,65535警告(22.35秒)
2)Ruby命令由于以下原因而失败:
column = "(MACHINE_NAME , TYPE_OF_ACTION , SCORE , FILE_PATH , MD5, REGKEY , VThit, action , action_result, action_result_detail, date)"
str = "Load data local infile " + "'" + "remediation_rewrite.csv" + "'" + " into table report.remediation" + " IGNORE 1 lines " + "#{column}" + ";";
p str
@con = Mysql.new("172.16.10.193", "myusername","xxx", "reporttdatabase")
@con.options(Mysql::OPT_LOCAL_INFILE, true)
rs = @con.query(str)
答案 0 :(得分:2)
根据'mysql2' gem documentation,出于安全原因,您需要将:local_infile
指定为true
(解释here,并引用here)。
将此替换为您的@con
客户端对象:
@con = Mysql2::Client.new(
host: "172.16.10.193",
username: "myusername",
password: "xxx",
database: "reporttdatabase",
local_infile: true
)