Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>INSERT INTO MY_TABLE(id, blob_col) VALUES(1, LOAD_FILE('/full/path/to/file/myfile.png') </code></pre> <p>LOAD_FILE has many conditions attached to it. From the <a href="http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_load-file" rel="nofollow noreferrer">MySQL documentation</a>:</p> <blockquote> <p>LOAD_FILE(file_name)</p> <p>Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. 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.</p> <p>If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns NULL.</p> </blockquote> <p>Also, there there are bugs with LOAD_FILE in Linux. See <a href="http://bugs.mysql.com/bug.php?id=38403" rel="nofollow noreferrer">http://bugs.mysql.com/bug.php?id=38403</a> for the bug, and <a href="https://stackoverflow.com/questions/4607486/mysql-load-file-returning-null">MySQL LOAD_FILE returning NULL</a> for workarounds. On Ubuntu 12.04, MySQL 5.5.32, this works for me:</p> <ol> <li>Copy file to /tmp</li> <li>Change ownership to mysql user <code>chown mysql:mysql /tmp/yourfile</code></li> <li>Log into mysql as mysql root user so you are sure you have FILE privilege</li> <li>Run your insert statement</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload