문제

I am developing Rails v2.3.2 with MySQL v5.1 on Ubuntu machine.

MySQL data directory is /var/lib/mysql/

I have a test.dat file located on /var/lib/mysql/tmp/test.dat

I would like to load data from the test.dat file into my database table, so I execute the following SQL statement in one of my rake task:

namespace :db do
  task :do_something => :environment do

    sql="LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat'
                INTO TABLE myapp.cars;"

    ActiveRecord::Base.connection.execute(sql);
  end
end

But I got the following error:

Mysql2::Error: Can't get stat of '/var/lib/mysql/tmp/test.dat' (Errcode: 2): LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat'

What could be the reason??

P.S. one thing come to my mind is that /var/lib/mysql/ can only be accessed by root user, but I am not sure if it is the reason.

도움이 되었습니까?

해결책

Try LOAD DATA LOCAL INFILE ....

다른 팁

As you mention the .dat has root access permission,
change it to 644 might help

Or check the user account that connecting mysql in ruby has the File privileges

select File_priv from mysql.user where Host=??? and user=???;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top