> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using SELECT INTO OUTFILE in MySQL

> Discover where to use MySQL's SELECT INTO OUTFILE and explore alternatives if your hosting package restricts it.

This article discusses using the **SELECT INTO OUTFILE** statement in MySQL.

## About SELECT INTO OUTFILE

The [SELECT INTO OUTFILE statement](https://mariadb.com/kb/en/select-into-outfile) writes the results of a query to a file. You can also specify custom column and row terminators to format the output.

## Support for SELECT INTO OUTFILE

**SELECT INTO OUTFILE** statements are supported on all unmanaged hosting packages, where you have complete control over the environment, including MySQL user privileges and configuration.

Shared and reseller hosting packages, however, do not allow you to run **SELECT INTO OUTFILE** statements. For security reasons, users are not granted the [FILE privilege](https://mariadb.com/kb/en/grant/#file), which is necessary to run **SELECT INTO OUTFILE** statements.

## Alternative to SELECT INTO OUTFILE

If your hosting package does not allow you to run **SELECT INTO OUTFILE** statements, you can still create files based on MySQL queries. To do this, simply redirect the SQL query output to a file from the command line. The following example demonstrates how to do this:

```shell theme={null}
echo "sql_query;" | mysql --user=mysql_username --password=mysql_password mysql_database > /home/username/query.txt
```

In this example, query output is redirected to the *query.txt* file. Make sure you use the following parameters correctly in your own commands:

* ***sql\_query***: This is the actual SQL query, such as "SELECT \* FROM employees;".

* ***mysql\_username***: This is the MySQL username for the database that you want to access.

* ***mysql\_password***: This is the password for the MySQL username you are using above.

* ***mysql\_database***: This is the name of the MySQL database that you want to access.

* ***username***: This is your hosting.com account username.

You can modify these values, including the path for the output file, to meet your own requirements.

## More information

For more information about **SELECT INTO OUTFILE**, please see the official documentation at [https://mariadb.com/kb/en/select-into-outfile](https://mariadb.com/kb/en/select-into-outfile).

## Related articles

* [Importing and exporting a MySQL database](/docs/import-and-export-a-mysql-database)

* [Managing MySQL databases and users](/docs/managing-mysql-databases)

* [Managing MySQL databases, users, and tables from the command line](/docs/managing-mysql-databases-and-users-from-the-command-line)
