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

# cockroach import

> [!CAUTION]
>
> 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`](https://docs.cockroachlabs.com/docs/v23.2/import-into) or [`COPY FROM`](https://docs.cockroachlabs.com/docs/v23.2/copy).

The `cockroach import` [command](https://docs.cockroachlabs.com/docs/v23.2/cockroach-commands.md) imports a database or table from a local dump file into a running cluster. This command [uploads a userfile](https://docs.cockroachlabs.com/docs/v23.2/cockroach-userfile-upload.md), imports its data, then [deletes the userfile](https://docs.cockroachlabs.com/docs/v23.2/cockroach-userfile-delete.md). `PGDUMP` and `MYSQLDUMP` file formats are currently supported.

## Required privileges

The user must have `CREATE` [privileges](https://docs.cockroachlabs.com/docs/v23.2/security-reference/authorization.md#managing-privileges) on `defaultdb`.

## Synopsis

Import a database:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import db <format> <location/of/file> <flags>
```

Import a table:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import table

```

View help:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import --help
```

## Supported formats

* [`pgdump`](https://docs.cockroachlabs.com/docs/molt/migrate-to-cockroachdb)
* [`mysqldump`](https://docs.cockroachlabs.com/docs/molt/migrate-to-cockroachdb?filters=mysql)

## Flags

| Flag | Description |
| - | - |
| `--certs-dir` | The path to the [certificate directory](https://docs.cockroachlabs.com/docs/v23.2/cockroach-cert.md) 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](https://docs.cockroachlabs.com/docs/v23.2/create-user.md) 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](https://docs.cockroachlabs.com/docs/v23.2/use-cloud-storage.md) or [userfile storage](https://docs.cockroachlabs.com/docs/v23.2/use-userfile-storage.md). |
| `--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:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import db mysqldump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
successfully imported mysqldump file /Users/maxroach/Desktop/test-db.sql
```

### Import a table

To import a table from a local file:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
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](https://docs.cockroachlabs.com/docs/v23.2/use-userfile-storage.md):

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ 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'
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
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:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs --row-limit='50'
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql
```

## See also

* [`cockroach` Commands Overview](https://docs.cockroachlabs.com/docs/v23.2/cockroach-commands)
* [`IMPORT`](https://docs.cockroachlabs.com/docs/v23.2/import)
* [`IMPORT INTO`](https://docs.cockroachlabs.com/docs/v23.2/import-into)
* [Migrate from PostgreSQL](https://docs.cockroachlabs.com/docs/molt/migrate-to-cockroachdb)
* [Migrate from MySQL](https://docs.cockroachlabs.com/docs/molt/migrate-to-cockroachdb?filters=mysql)
