Question

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.

Was it helpful?

Solution

Try LOAD DATA LOCAL INFILE ....

OTHER TIPS

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=???;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top