Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to be able to load files to the database using SQL (mysql) from a web directory (apache httpdocs directory) on a centos machine that runs apache, mysql and plesk.

I understand I need to give the mysql database user FILE permissions on .

but how can I give the mysql server (probably mysqld) access to the httpdocs folder and the files inside (httpdocs is owned by one user and everything inside is owned by apache).

share|improve this question

3 Answers 3

I think you don't need that.

mysql (the client), will be run as the user u selected (apache?), and that user must have read permissions over the files so they can be readed & imported into mysql server.

The server doesn't nead read this files, is the user running mysql client who needs the perms.

share|improve this answer
    
The code is run by a php script that uses mysql to access a local file (on the server) and load it. –  Dani Dec 16 '09 at 14:46
    
Then the web server user(apache) will need read permissions on the file and execute permissions on all the directories above the file. –  Kevin M Dec 16 '09 at 15:04
    
if you are running a php script using php directly on the machine instead of through apache then the script is running as whatever user invoked the script. I believe that is the user that will need access. The accepted way to give them access is to make them part of the group that owns the file and then give that group read permissions on the file (if they don't already have them) using chmod. –  Catherine MacInnes Dec 16 '09 at 15:15

If it is a mysql dump file that you are importing, you can do:

system("mysql -u username -ppassword databasename < /path/to/file.sql");

Otherwise, you can write something to run through the file, parse it and insert each of the lines into your database.

share|improve this answer
    
This is not the case... –  Dani Mar 26 '10 at 9:02

I'm assuming you're trying to use the LOAD DATA INFILE command. If this is the case then as the documentation states:

"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.4.1, “Privileges Provided by MySQL”. For non-LOCAL load operations, if the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory."

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

This indicates that the file must be set to readable by all.

share|improve this answer
    
Tried that, evntually, I've put the file in a /var/temp directory and chmod everything to 777 and only that solved the problem. I wanted to load that file from the site's httpdocs directory. –  Dani Mar 26 '10 at 9:03

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.