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

What is the mysql function for reading file content?

下次还敢
Release: 2024-04-22 19:33:18
Original
597 people have browsed it

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>
Copy after login

Example:

<code>SELECT LOAD_FILE('/path/to/file.txt');</code>
Copy after login

2. FILE()

FILE() Function is similar to LOAD_FILE(), but it can read binary files.

Syntax:

<code>FILE(filepath)</code>
Copy after login

Example:

<code>SELECT FILE('/path/to/binary_file.dat');</code>
Copy after login

3. INTO OUTFILE

INTO OUTFILE statement will The query results are written to the specified file.

Grammar:

<code>SELECT ... INTO OUTFILE 'filepath';</code>
Copy after login

Example:

<code>SELECT * FROM table INTO OUTFILE '/path/to/output_file.csv';</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template