Home >Database >Mysql Tutorial >Which is the function of mysql to read files?
MySQL’s function for reading file contents is LOAD_FILE(). This function returns the contents of the file as a text string by accepting a file path as a parameter. The syntax is: LOAD_FILE(file_path). It can read local files, but requires read permission. Note that this function may return incorrect results, such as the file does not exist or contains binary data.
Which is the function for reading files in MySQL?
The function in MySQL to read the contents of a file is LOAD_FILE()
.
Detailed explanation:
LOAD_FILE()
The function accepts a file path as a parameter and returns the contents of the file as a text string. This function can be used with the following syntax:
<code>LOAD_FILE(file_path)</code>
where file_path
is the absolute path to the file to be read.
Usage example:
The following example uses the LOAD_FILE()
function to read the content from the file my_data.txt
and Store it in the variable file_content
:
<code class="sql">SET @file_content = LOAD_FILE('/path/to/my_data.txt');</code>
Now the variable @file_content
will contain the content from the my_data.txt
file.
Note:
LOAD_FILE()
The function can only read local files, not remote files. NULL
. The above is the detailed content of Which is the function of mysql to read files?. For more information, please follow other related articles on the PHP Chinese website!