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_DIRDefault: ${HOME}/.cockroach-certs/ |
--insecure |
Use an insecure connection. Env Variable: COCKROACH_INSECUREDefault: false |
--user-u |
The SQL user that will own the client session. Env Variable: COCKROACH_USERDefault: 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:
$ 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:
$ 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:
$ 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:
$ 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