Bug #31670 ERROR 13 (HY000): Can't get stat of '/tmp/test.txt' (Errcode: 13)
Submitted: 17 Oct 2007 17:06 Modified: 21 Nov 2007 13:18
Reporter: Donovan Hsieh Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.1.22-0 OS:Linux (Redhat EL4)
Assigned to:

[17 Oct 2007 17:06] Donovan Hsieh
Description:
-bash-3.00$ ll /tmp/test.txt 
-rwxrwxrwx  1 mysql mysql 10180 Oct 17 09:37 /tmp/test.txt
-bash-3.00$ mysql dars -uroot
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.22-rc-community MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> load data infile '/tmp/test.txt' into table core_dars fields terminated by ',';
ERROR 13 (HY000): Can't get stat of '/tmp/test.txt' (Errcode: 13)

How to repeat:
-bash-3.00$ ll /tmp/test.txt 
-rwxrwxrwx  1 mysql mysql 10180 Oct 17 09:37 /tmp/test.txt
-bash-3.00$ mysql dars -uroot
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.22-rc-community MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> load data infile '/tmp/test.txt' into table core_dars fields terminated by ',';
ERROR 13 (HY000): Can't get stat of '/tmp/test.txt' (Errcode: 13)
[17 Oct 2007 17:49] Miguel Solorzano
Thank you for the bug report. That sounds as permission issue:

[miguel@skybr 5.1]$ bin/perror 13
OS error code  13:  Permission denied

Please see: http://dev.mysql.com/doc/refman/5.1/en/load-data.html

"For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege. See Section 5.7.3, “Privileges Provided by MySQL”."
[17 Oct 2007 19:17] Donovan Hsieh
As you can see from the screen capture text, the input file '/tmp/dars.txt' has rwxrwxrwx and it is located in /tmp directory. Also, I login as root from console shell and it has "GRANT FILE ON *.* TO `root`@`localhost`" privilege. I still think it is a BUG.
[18 Oct 2007 8:17] Sveta Smirnova
Thank you for the feedback.

I can not repeat described behaviour in myself environment.

Please provide output of ls -lad /tmp and stat /tmp/test.txt commands.
[18 Oct 2007 15:23] Donovan Hsieh
rac1-> ls -lad /tmp 
drwxrwxrwt  7 root root 4096 Oct 18 08:19 /tmp
rac1-> stat /tmp/test.txt 
  File: `/tmp/test.txt'
  Size: 10180           Blocks: 32         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 528666      Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (  100/   mysql)   Gid: (  101/   mysql)
Access: 2007-10-17 10:52:19.000000000 -0700
Modify: 2007-10-17 09:37:23.000000000 -0700
Change: 2007-10-17 09:49:36.000000000 -0700
rac1-> ll /tmp/test.txt
-rwxrwxrwx  1 mysql mysql 10180 Oct 17 09:37 /tmp/test.txt
rac1-> mysql dars -uroot
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.22-rc-community MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show tables;
+----------------+
| Tables_in_dars |
+----------------+
| core_dars      | 
+----------------+
1 row in set (0.01 sec)

mysql> load data infile '/tmp/test.txt' into table core_dars fields terminated by ',' lines terminated by '\r\n';
ERROR 13 (HY000): Can't get stat of '/tmp/test.txt' (Errcode: 13)
mysql>
[18 Oct 2007 15:26] Donovan Hsieh
I am not sure if this makes any difference. The MySQL server running on Redhat EL4 is actually a CentOS4. They are essential the same linux kernel. Also, The MySQL also runs under the VMWare Server Linux client OS with WinXP as its host OS.
[20 Oct 2007 12:32] Sveta Smirnova
Thank you for the feedback.

Please indicate accurate version of the package you use and output of SELECT @@secure_file_priv; and SELECT @@global.secure_file_priv;
[21 Nov 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[21 Nov 2007 13:18] Sveta Smirnova
Closed as "Can't repeat" as no feedback provided and I can not repeat error with further testing
[4 Jan 2008 16:58] Thomas Whatever
I have the same problem on SuSE Linux 9.3

mysql> LOAD DATA INFILE "/home/ipnicks_uwc3" INTO TABLE uwc3_incoming FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
ERROR 13 (HY000): Can't get stat of '/home/ipnicks_uwc3' (Errcode: 2)

Directory and file are world-readable (strange requirement!):

drwxr-xr-x  17 root root 4096 Jan  4 17:50 /home/
-rw-r--r--  1 web1 tomcat 100 Jan  4 17:51 /home/ipnicks_uwc3

MySQL used:
mysql  Ver 14.7 Distrib 4.1.21, for pc-linux-gnu (i686) using readline 4.3

Several scripts do not run for over a year now because of this error ...
:-/
In an earlier version of MySQL that worked flawlessly!
[30 Mar 2008 18:08] Martin Manscher
I also struggled with this. Turns out you need the file _and_ directory to be world-readable:

chmod 755 .
chmod 744 file.dat
[11 Jul 2008 15:00] George Cooke
All parent directories of the infile need world-readable I think aswell as just the directory and infile, mine did on CentOS 4.3 with MySQL 4.1.12-log (from Plesk).

So for an infile here:
/tmp/imports/site1/data.file

you would need (I think, 755 worked) r+x for 'other' on these directories:
/tmp
/tmp/imports

as well as the main two:
/tmp/imports/site1
/tmp/imports/site1/data.file
[15 Sep 2008 20:47] Omid Noorani
Thank you. It worked for and solved my problem.
[6 Aug 2009 17:05] Yuvraj kc
Actually the syntaxt was wrong.
use this command to load the data into mysql from a file.

mysql> LOAD DATA INFILE '/root/t.txt' INTO TABLE temp_table;
ERROR 13 (HY000): Can't get stat of '/root/t.txt' (Errcode: 13)

mysql> LOAD DATA local INFILE '/root/tt.sql' INTO TABLE temp_table;
Query OK, 737 rows affected, 737 warnings (0.01 sec)
Records: 737  Deleted: 0  Skipped: 0  Warnings: 721
[25 Feb 2011 16:33] Parikshit Tiwari
I installed mysql in ubuntu 10.10 and wanted to create a database, I am getting the following error

mysql> CREATE DATABASE project_whip;
ERROR 13 (HY000): Can't get stat of './project_whip' (Errcode: 13)