MySQL provides three functions to read the file content: LOAD_FILE(): Read the text file content and return it as a string. FILE(): Similar to LOAD_FILE(), but can read binary files. INTO OUTFILE: Write query results to the specified file.
MySQL read file content function
MySQL provides several functions for reading file content:
1. LOAD_FILE()
LOAD_FILE()
The function reads the file content from the specified file path and returns it as a string.
Syntax:
<code>LOAD_FILE(filepath)</code>
Example:
<code>SELECT LOAD_FILE('/path/to/file.txt');</code>
2. FILE()
FILE()
Function is similar to LOAD_FILE()
, but it can read binary files.
Syntax:
<code>FILE(filepath)</code>
Example:
<code>SELECT FILE('/path/to/binary_file.dat');</code>
3. INTO OUTFILE
INTO OUTFILE
statement will The query results are written to the specified file.
Grammar:
<code>SELECT ... INTO OUTFILE 'filepath';</code>
Example:
<code>SELECT * FROM table INTO OUTFILE '/path/to/output_file.csv';</code>
The above is the detailed content of What is the mysql function for reading file content?. For more information, please follow other related articles on the PHP Chinese website!