docs/content/stable/manage/backup-restore/export-import-data-ycql.md
You use the ycqlsh script to export and import YCQL data. For details on how to use the script to connect to a YugabyteDB cluster, as well as the full list of available options, see ycqlsh reference.
You use the DESCRIBE command (abbreviated to DESC) to export the schema.
To export the schema of a single keyspace, run the following command:
./bin/ycqlsh -e "DESC KEYSPACE <keyspace_name>" > <file>
To export the schema of every keyspace, run the following command:
ycqlsh -e "DESC SCHEMA" > <file>
file is the path to the resulting CQL script file.
To export your data, use the COPY TO command that queries all rows of the specified table and writes into a comma-separated values (CSV) file.
The following is a full syntax of the COPY TO command:
COPY table_name [( column_list )]
TO 'file_name'[, 'file2_name', ...] | STDIN
[WITH option = 'value' [AND ...]]
The command supports multiple options. The following table outlines some of the more commonly used ones.
| Option | Description | Default value |
|---|---|---|
DELIMITER | Field separator character. | , (comma) |
HEADER | If true, output column names as the first row of data. | false |
PAGESIZE | Page size for fetching results. | 1000 |
PAGETIMEOUT | Page timeout for fetching results. | 10 |
MAXREQUESTS | Maximum number of requests each worker processes in parallel. | 6 |
MAXOUTPUTSIZE | Maximum number of lines in the output file. | |
| When set, the output file is split into segments no larger than this value. | ||
Use -1 for no maximum. | -1 |
To import a schema, use the SOURCE command, as follows:
ycqlsh -e "SOURCE '<file>'"
file is the path to the CQL script file from which to import the schema.
After you import the schema, use the COPY FROM command to import the actual data from one or more CSV files.
The following is a full syntax of the COPY FROM command:
COPY table_name [( column_list )]
FROM 'file_name'[, 'file2_name', ...] | STDIN
[WITH option = 'value' [AND ...]]
The following table lists commonly-used options.
| Option | Description | Default |
|---|---|---|
DELIMITER | Field separator character. | , (comma) |
HEADER | If true, the first row of data contains column names. | false |
CHUNKSIZE | Maximum number of rows each insert. | 1000 |
INGESTRATE | Desired ingestion rate in rows per second. | |
Must be greater than CHUNKSIZE. | 100000 |