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

# cockroach import

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

<Danger>
  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 <InternalLink path="import-into">`IMPORT INTO`</InternalLink> or <InternalLink path="copy">`COPY FROM`</InternalLink>.
</Danger>

The `cockroach import` <InternalLink path="cockroach-commands">command</InternalLink> imports a database or table from a local dump file into a running cluster. This command <InternalLink path="cockroach-userfile-upload">uploads a userfile</InternalLink>, imports its data, then <InternalLink path="cockroach-userfile-delete">deletes the userfile</InternalLink>. `PGDUMP` and `MYSQLDUMP` file formats are currently supported.

## Required privileges

The user must have `CREATE` <InternalLink path="security-reference/authorization#managing-privileges">privileges</InternalLink> 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 <table_name> <format> <location/of/file> <flags>
```

View help:

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

## Supported Formats

* <InternalLink version="molt" path="migrate-to-cockroachdb">`pgdump`</InternalLink>
* <InternalLink version="molt" path="migrate-to-cockroachdb?filters=mysql">`mysqldump`</InternalLink>

## Flags

| Flag                              | Description                                                                                                                                                                                                                                               |
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--certs-dir`                     | The path to the <InternalLink path="cockroach-cert">certificate directory</InternalLink> containing the CA and client certificates and client key.<br /><br />**Env Variable:** `COCKROACH_CERTS_DIR`<br />**Default:** `${HOME}/.cockroach-certs/`       |
| `--insecure`                      | Use an insecure connection.<br /><br />**Env Variable:** `COCKROACH_INSECURE`<br />**Default:** `false`                                                                                                                                                   |
| `--user`<br />`-u`                | The <InternalLink path="create-user">SQL user</InternalLink> that will own the client session.<br /><br />**Env Variable:** `COCKROACH_USER`<br />**Default:** `root`                                                                                     |
| `--ignore-unsupported-statements` | Ignore statements that are unsupported during an import from a PGDUMP file. <br />**Default:** `false`                                                                                                                                                    |
| `--log-ignored-statements`        | Log statements that are ignored during an import from a PGDUMP file to the specified destination (i.e., <InternalLink path="use-cloud-storage">cloud storage</InternalLink> or <InternalLink path="use-userfile-storage">userfile storage</InternalLink>. |
| `--row-limit=`                    | The number of rows to import for each table during a PGDUMP or MYSQLDUMP import. <br /> This can be used to check schema and data correctness without running the entire import. <br />**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
```

```
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
```

```
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 <InternalLink path="use-userfile-storage">userfile</InternalLink>:

```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'
```

```
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'
```

```
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql
```

## See also

* <InternalLink path="cockroach-commands">`cockroach` Commands Overview</InternalLink>
* <InternalLink path="import">`IMPORT`</InternalLink>
* <InternalLink path="import-into">`IMPORT INTO`</InternalLink>
* <InternalLink version="molt" path="migrate-to-cockroachdb">Migrate from PostgreSQL</InternalLink>
* <InternalLink version="molt" path="migrate-to-cockroachdb?filters=mysql">Migrate from MySQL</InternalLink>
