SELECT INTO DUMPFILE

You are viewing an old version of this article. View the current version here.

INTO DUMPFILE is a SELECT clause which tells causes the resultset to be saved into a file. The results will not be returned to the client.

The syntax is:

SELECT ... INTO DUMPFILE 'file_path'

file_path can be an absolute path, or a relative path starting from the data directory.

This statement is binary-safe. It can be used, for example, to copy an image or an audio document from the database to a file. SELECT ... INTO FILE can be used to save a text file.

The resultset must consist of zero or one row. Resultsets consisting of multiple columns are allowed. In this case, the values will be written in the file without any separator.

The file must not exist. It cannot be overwritten. A user needs the SUPER privilege to run this statement. Also, MariaDB needs the permissions to write a file in the specified location.

Example

SELECT _utf8'Hello world!' INTO DUMPFILE '/tmp/world';

SELECT LOAD_FILE('/tmp/world') AS world;
+--------------+
| world        |
+--------------+
| Hello world! |
+--------------+

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.