# SELECT INTO DUMPFILE

## Syntax

```sql
SELECT ... INTO DUMPFILE 'file_path'
```

## Description

`SELECT ... INTO DUMPFILE` is a [SELECT](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select) clause which writes the resultset into a single unformatted row, without any separators, in a file. The results will not be returned to the client.

*file\_path* can be an absolute path, or a relative path starting from the data directory. It can only be specified as a [string literal](https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/string-literals), not as a variable. However, the statement can be dynamically composed and executed as a prepared statement to work around this limitation.

This statement is binary-safe and so is particularly useful for writing [BLOB](https://mariadb.com/docs/server/reference/data-types/string-data-types/blob) values to file. It can be used, for example, to copy an image or an audio document from the database to a file.

The file must not exist. It cannot be overwritten. A user needs the [FILE](https://mariadb.com/docs/server/reference/account-management-sql-statements/grant#global-privileges) privilege to run this statement. Also, MariaDB needs permission to write files in the specified location. If the [secure\_file\_priv](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#secure_file_priv) system variable is set to a non-empty directory name, the file can only be written to that directory.

{% tabs %}
{% tab title="Current" %}
The [character\_set\_filesystem](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#character_set_filesystem) system variable has controlled interpretation of file names that are given as literal strings.
{% endtab %}

{% tab title="< 5.1" %}
The [character\_set\_filesystem](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#character_set_filesystem) system variable does not have controlled interpretation of file names that are given as literal strings.
{% endtab %}
{% endtabs %}

## Example

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

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

## See Also

* [SELECT](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select)
* [LOAD\_FILE()](https://mariadb.com/docs/server/reference/sql-functions/string-functions/load_file)
* [SELECT INTO Variable](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/selectinto)
* [SELECT INTO OUTFILE](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select-into-outfile)

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select-into-dumpfile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
