cockroach import

On this page Carat arrow pointing down
Warning:

The statements on this page are deprecated as of v23.1 and will be removed in a future release. To move data into CockroachDB, use IMPORT INTO or COPY FROM.

The cockroach import command imports a database or table from a local dump file into a running cluster. This command uploads a userfile, imports its data, then deletes the userfile. PGDUMP and MYSQLDUMP file formats are currently supported.

Required privileges

The user must have CREATE privileges on defaultdb.

Synopsis

Import a database:

$ cockroach import db <format> <location/of/file> <flags>

Import a table:

$ cockroach import table <table_name> <format> <location/of/file> <flags>

View help:

$ cockroach import --help

Supported Formats

Flags

Flag Description
--certs-dir The path to the certificate directory containing the CA and client certificates and client key.

Env Variable: COCKROACH_CERTS_DIR
Default: ${HOME}/.cockroach-certs/
--insecure Use an insecure connection.

Env Variable: COCKROACH_INSECURE
Default: false
--user
-u
The SQL user that will own the client session.

Env Variable: COCKROACH_USER
Default: root
--ignore-unsupported-statements Ignore statements that are unsupported during an import from a PGDUMP file.
Default: false
--log-ignored-statements Log statements that are ignored during an import from a PGDUMP file to the specified destination (i.e., cloud storage or userfile storage.
--row-limit= The number of rows to import for each table during a PGDUMP or MYSQLDUMP import.
This can be used to check schema and data correctness without running the entire import.
Default: 0

Examples

Import a database

To import a database from a local file:

icon/buttons/copy
$ cockroach import db mysqldump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
successfully imported mysqldump file /Users/maxroach/Desktop/test-db.sql

Import a table

To import a table from a local file:

icon/buttons/copy
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

Import a database with unsupported SQL syntax and log all unsupported statements

To import a database from a PGDUMP file that contains unsupported SQL syntax and log the ignored statements to a userfile:

icon/buttons/copy
$ cockroach import db pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs --ignore-unsupported-statements=true --log-ignored-statements='userfile://defaultdb.public.userfiles_root/unsupported-statements.log'
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

Import a limited number of rows from a dump file

To limit the number of rows imported from a dump file:

icon/buttons/copy
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs --row-limit='50'
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

See also


Yes No
On this page

Yes No