Jump to content

Import large CSV into MYSQL / Access directory outside web root


enveetee

Recommended Posts

I am trying to upload a large dataset in CSV format for batch loading into a MYSQL table using LOAD DATA INFILE


 


The CSV file (test.csv) is in


/var/services/web/php


 


My table is in


/var/services/mysql/TABLENAME


 


When I run the SQL command from a PHP script I get an error ERROR: Can't get stat of '/var/services/mysql/TABLENAME/test.csv' (Errcode: 2) Which I believe is because the file needs to be in /var/services/mysql/TABLENAME. Indeed, if I move it there, it works fine


 


If I try and use the LOCAL switch LOAD DATA LOCAL INFILE I get an error stating that feature is not available. Research shows it can cause a security hole and needs to be enabled separately, something I am not prepared to do


 


I cant copy the file in my PHP script to /var/services/mysql/TABLENAME as it is outside or /var/services/web


 


So short of manually copying the FTP'd file to my table directory, how could I copy it from my PHP script?


 


This also leads to my second question 'how do I access files outside my web root'


 


Thanks


Link to comment
Share on other sites

The php user for that site, or the group the user belongs to, needs to have read/write permissions for whatever dir they are trying to access outside of that users "home". Well probably just read permissions if you are manually uploading the file. Otherwise any php user on the server, for any website, can read/write each others files, which is like NO security.

Edited by CroNiX
Link to comment
Share on other sites

PHP runs under a certain user account. On Linux it's usually www-data (which is what apache usually runs under, and thus PHP). But this could be different. On Windows/IIS it's usually IUSR_MACHINE. Whatever the user account is, it has to have permission to access the file.

Edited by raphael75
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.