> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# How do I export MySQL data to Parquet, CSV, or JSON using ClickHouse

> Learn how to use the `clickhouse-local` tool to export MySQL data into formats like Parquet, CSV, or JSON quickly and efficiently.

{frontMatter.description}

<h2 id="exporting-mysql-data-to-parquet-csv-or-json-using-clickhouse">
  Exporting MySQL Data to Parquet, CSV, or JSON Using ClickHouse
</h2>

The `clickhouse-local` tool makes it quick and easy to read data from MySQL and output the data into lots of different formats, including Parquet, CSV, and JSON. We are going to:

* Use the [`mysql` table function](/reference/functions/table-functions/mysql) to read the data
* Use the `INTO OUTFILE _filename_ FORMAT` clause and specify the desired output format

The `clickhouse-local` tool is a part of the ClickHouse binary. Download it using the following:

```bash theme={null}
curl https://clickhouse.com/ | sh
```

<h2 id="export-mysql-to-parquet">
  Export MySQL to Parquet
</h2>

The `mysql` table function creates a table based on the results of a query sent to a MySQL instance. For example:

```bash theme={null}
SELECT *
FROM
   mysql(
    'localhost:3306',
    'my_sql_database',
    'my_sql_table',
    'user',
    'password'
);
```

We can pipe the output of this query to a file using `INTO OUTFILE`. Use `FORMAT` to specify the format of the file to be created. Let's grab the entire contents of a MySQL table, and send its contents to a Parquet file:

```bash theme={null}
./clickhouse local -q "SELECT * FROM
   mysql(
    'localhost:3306',
    'my_sql_database',
    'my_sql_table',
    'user',
    'password'
)
INTO OUTFILE 'my_output_file.parquet'"
```

<Note>
  Because the name of the output file has a `.parquet` extension, ClickHouse assumes we want the Parquet format, so notice we omitted the `FORMAT Parquet` clause.
</Note>

<h2 id="export-mysql-to-csv">
  Export MySQL to CSV
</h2>

It's the same as for Parquet, except this time we use a `.csv` extension on the filename. ClickHouse will realize we want a comma-separated output and that's how the data will be written to the file:

```bash theme={null}
./clickhouse local -q "SELECT * FROM
   mysql(
    'localhost:3306',
    'my_sql_database',
    'my_sql_table',
    'user',
    'password'
)
INTO OUTFILE 'my_output_file.csv'"
```

<h2 id="export-mysql-to-json">
  Export MySQL to JSON
</h2>

To go from MySQL to JSON, just change the extension on the filename to `jsonl` or `ndjson`:

```bash theme={null}
./clickhouse local -q "SELECT * FROM
   mysql(
    'localhost:3306',
    'my_sql_database',
    'my_sql_table',
    'user',
    'password'
)
INTO OUTFILE 'my_output_file.ndjson'"
```

It's impressive how simple yet powerful the `clickhouse-local` tool really is. You can easily read data from a database like MySQL and output it into [all types of different output formats](/reference/formats/index).
