> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select-into-dumpfile.md).

# SELECT INTO DUMPFILE

## Syntax

```bnf
SELECT ... INTO DUMPFILE 'file_path'
```

## Description

`SELECT ... INTO DUMPFILE` is a [SELECT](/docs/server/reference/sql-statements/data-manipulation/selecting-data/select.md) 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](/docs/server/reference/sql-structure/sql-language-structure/string-literals.md), 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](/docs/server/reference/data-types/string-data-types/blob.md) 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](/docs/server/reference/sql-statements/account-management-sql-statements/grant.md#global-privileges) privilege to run this statement. Also, MariaDB needs permission to write files in the specified location. If the [secure\_file\_priv](/docs/server/server-management/variables-and-modes/server-system-variables.md#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](/docs/server/server-management/variables-and-modes/server-system-variables.md#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](/docs/server/server-management/variables-and-modes/server-system-variables.md#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](/docs/server/reference/sql-statements/data-manipulation/selecting-data/select.md)
* [LOAD\_FILE()](/docs/server/reference/sql-functions/string-functions/load_file.md)
* [SELECT INTO Variable](/docs/server/reference/sql-statements/programmatic-compound-statements/selectinto.md)
* [SELECT INTO OUTFILE](/docs/server/reference/sql-statements/data-manipulation/selecting-data/select-into-outfile.md)

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

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