MySQL Forums
Forum List  »  General

LOAD_FILE() only works on Windows, not Linux
Posted by: Harald Groven
Date: July 13, 2008 05:03PM

I regularly import files from the file system to mysql databases using the LOAD_FILE() function. It works fine on Windows, but when I tried to do the same on Linux no data is read. File paths seems to be valid, permissions ok, backslashes on win file paths and forward slashes in linux filpaths, but only Windows behave as expected.

Win:

mysql> CREATE TABLE files (
-> `filepath` varchar(200) NOT NULL, -- path to file in local filesystem
-> `html` longtext -- a text field to store data
-> ) ;

Query OK, 0 rows affected (0.05 sec)

mysql>
mysql> INSERT INTO `files` (`filepath`, `html`) VALUES
-> ('C:\\temp\\somefile.html', NULL);

Query OK, 1 row affected (0.00 sec)


mysql>
mysql> UPDATE files
-> SET html=LOAD_FILE(filepath)
-> ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0





LINUX

me@my-laptop:~$ chmod 777 somefile.html
me@my-laptop:~$ ls -l
...
-rwxrwxrwx 1 me me 21 2008-07-14 00:46 somefile.html


mysql> CREATE TABLE files (
-> `filepath` varchar(200) NOT NULL,
-> `html` longtext
-> ) ;
Query OK, 0 rows affected (0.00 sec)


mysql> INSERT INTO `files` (`filepath`, `html`) VALUES
-> ('~/somefile.html', NULL),
-> ('/home/myusername/somefile.html', NULL)
-> ;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql>
mysql> UPDATE files
-> SET html=LOAD_FILE(filepath) ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0


mysql>

No data imported to the column html :-(

What's wrong here? Mysql or Linux (Ubuntu) ?

Options: ReplyQuote


Subject
Written By
Posted
LOAD_FILE() only works on Windows, not Linux
July 13, 2008 05:03PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.