![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a file that I'm grabbing by FTP via cron, then formatting via PHP. Then, also in PHP, I'm trying to import the formatted CSV file into that table. Here's the query that I'm using (I'm leaving it in PHP, just in case you see a problem with the escaping): $local_file = "/home/myacct/www/dir/file.csv"; $upload = "LOAD DATA INFILE \"$local_file\" "; $upload .= "INTO TABLE table "; $upload .= "FIELDS TERMINATED BY ',' "; $upload .= "ENCLOSED BY '\"' ESCAPED BY '\\\\' "; $upload .= "LINES TERMINATED BY '\\n';"; $sth = mysql_query($upload); if (!$sth) die(mysql_error()); This script gives me the error of: Can't get stat of '[filename]' (Errcode: 13) I've been researching this error, and it seems like the most common explanation is a failed permission. But, I did give the user FILE permission, using (as root): GRANT FILE ON *.* TO [username]@localhost IDENTIFIED BY '[password]'; I also ensured that $local_file is chmod to 0755. Any suggestions? |
#3
| |||
| |||
|
|
On 17 Nov 2011 in comp.databases.mysql, Jason C wrote: I have a file that I'm grabbing by FTP via cron, then formatting via PHP. Then, also in PHP, I'm trying to import the formatted CSV file into that table. Here's the query that I'm using (I'm leaving it in PHP, just in case you see a problem with the escaping): $local_file = "/home/myacct/www/dir/file.csv"; $upload = "LOAD DATA INFILE \"$local_file\" "; $upload .= "INTO TABLE table "; $upload .= "FIELDS TERMINATED BY ',' "; $upload .= "ENCLOSED BY '\"' ESCAPED BY '\\\\' "; $upload .= "LINES TERMINATED BY '\\n';"; $sth = mysql_query($upload); if (!$sth) die(mysql_error()); This script gives me the error of: Can't get stat of '[filename]' (Errcode: 13) I've been researching this error, and it seems like the most common explanation is a failed permission. But, I did give the user FILE permission, using (as root): GRANT FILE ON *.* TO [username]@localhost IDENTIFIED BY '[password]'; I also ensured that $local_file is chmod to 0755. Any suggestions? http://www.google.com/search?q=mysql+can't+get+stat+of+errcode+13 leads to: http://bugs.mysql.com/bug.php?id=31670 which suggests using 'LOAD DATA local INFILE ...' I got errorcode 2 on my server, which led more directly to the answer: http://stackoverflow.com/questions/3...file-errcode-2 try running the command manually without php involved |
#4
| |||
| |||
|
|
$local_file = "/home/myacct/www/dir/file.csv"; $upload = "LOAD DATA INFILE \"$local_file\" "; |
|
This script gives me the error of: Can't get stat of '[filename]' (Errcode: 13) I've been researching this error, and it seems like the most common explanation is a failed permission. But, I did give the user FILE permission, using (as root): I also ensured that $local_file is chmod to 0755. |
#5
| |||
| |||
|
|
http://www.google.com/search?q=mysql+can't+get+stat+of+errcode+13 leads to: http://bugs.mysql.com/bug.php?id=31670 which suggests using 'LOAD DATA local INFILE ...' I got errorcode 2 on my server, which led more directly to the answer: http://stackoverflow.com/questions/3...file-errcode-2 -- Joe Makowiec |
#6
| |||
| |||
|
|
try running the command manually without php involved Its not clear what is going on here. |
#7
| |||
| |||
|
|
I also ensured that $local_file is chmod to 0755. ~ $perror 13 OS error code 13: Permission denied So obviously something is wrong with file permissions. It must be world-readable (because it's outside datadir). Check also the directory where the file resides. Must be readable by the user that runs the MySQL server. See http://dev.mysql.com/doc/refman/5.1/en/load-data.html |
#8
| |||
| |||
|
|
On Thursday, November 17, 2011 7:37:20 AM UTC-5, Axel Schwenke wrote: ~ $perror 13 OS error code 13: Permission denied So obviously something is wrong with file permissions. By default, all of my public directories are created at 0755. I double checked, and yes, it's definitely world-readable. When I FTP to the file as root, though, I see that file.csv has an Owner/Group of root/root (where the PHP file is user/user). Could that be a problem? |
#9
| |||
| |||
|
|
On Thursday, November 17, 2011 7:19:12 AM UTC-5, Joe Makowiec wrote: http://www.google.com/search?q=mysql+can't+get+stat+of+errcode+13 leads to: http://bugs.mysql.com/bug.php?id=31670 which suggests using 'LOAD DATA local INFILE ...' I got errorcode 2 on my server, which led more directly to the answer: http://stackoverflow.com/questions/3...file-errcode-2 -- Joe Makowiec I had actually found that link before, too. I tried to use LOAD DATA LOCAL INFILE last night, but then quickly discovered that I have it disabled for security purposes (due to a strong suggestion from my firewall). I'm not sure what the security problem is with it, but is this something that should be re-enabled? Is there no other way to do what I need without it? |
![]() |
| Thread Tools | |
| Display Modes | |
| |