Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using 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:

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

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted
$ ls -ld /var/lib/mysql
drwx------ 21 mysql mysql 4096 2011-11-18 14:07 /var/lib/mysql

Yes, you have no permissions for that directory (it may be root:root depending on your setup). Use:

sudo mysql -u mysqluser -e "LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat' INTO TABLE myapp.cars;"

Or just copy the file to your home directory (or wherever) and chown it to yourself.

share|improve this answer

if your file is on localhost, use

LOAD DATA LOCAL INFILE ...

instead of LOAD DATA INFILE.

Plus, have the file permission to be readable by mysql user, and plus have this run by mysql root:

GRANT FILE ON *.* to <your_db_user_name>@localhost;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.