Home >Database >Mysql Tutorial >What is the mysql function for reading file content?

What is the mysql function for reading file content?

下次还敢
下次还敢Original
2024-04-22 19:33:18635browse

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.

What is the mysql function for reading file content?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn