# How to import data to SQL Database

import Tabs from '~/components/tabs/Tabs';
import DocButton from '~/components/webkit/DocButton.vue';

 This guide explains how to import data into your database using SQL Database Shell.

## Requirements

- **SQL Database Shell Installed**: Ensure that you have the SQL Database shell properly [installed on your system](/en/documentation/products/store/sql/install-edge-sql-shell/).

- **Database Setup**: You need to have a database created. To create a new database within SQL Database using the Shell, use the command:
```sh
  .create <database-name>
```

## Importing Data with SQL Database Shell

<Tabs client:visible sharedStore="Databases">
<fragment slot="tab.file">CSV or XLSX</fragment>
<fragment slot="tab.kaggle">Kaggle</fragment>
<fragment slot="tab.mysql">MySQL</fragment>
<fragment slot="tab.sqlite">SQLite</fragment>
<fragment slot="tab.postgres">Postgres</fragment>
<fragment slot="tab.turso">Turso</fragment>

<fragment slot="panel.file">
<slot name="file" />

1. Select a SQL Database database.

```shell
.use database-name
```

2. Import your file.
```
.import file <csv|xlsx> <file_path> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```
</fragment>

<fragment slot="panel.kaggle">
<slot name="Kaggle" />

1. Select a SQL Database database.

```shell
.use database-name
```

2. Import your kaggle database.

Use the following commands to set enviroment variables with your Kaggle credentials:

```sh
  export KAGGLE_USERNAME="<username>"
  export KAGGLE_KEY="<kaggle_api_key>"
```

```shell
.import kaggle <dataset> <data_name> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```
</fragment>

<fragment slot="panel.mysql">
<slot name="MySQL" />

Use the following commands to set enviroment variables with your MySQL credentials:

```sh
  export MYSQL_USERNAME="<username>"
  export MYSQL_PASSWORD="<password>"
  export MYSQL_HOST="<host_address>"
```

Optional settings for MySQL:

```sh
  export MYSQL_PORT=<port>
  
  # For TLS connection
  export MYSQL_SSL_CA="<ssl_ca>"
  export MYSQL_SSL_CERT="<ssl_cert>"
  export MYSQL_SSL_KEY="<ssl_key>"
  export MYSQL_SSL_VERIFY_CERT=<True|False>
```

1. Select a SQL Database database.

```shell
.use database-name
```

2. Import your MySQL database.

```shell
.import mysql <database> <source_table> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```

</fragment>
<fragment slot="panel.postgres">
<slot name="Postgres" />

1. Select a SQL Database database.

Use the following commands to set enviroment variables with your PostgreSQL credentials:

```sh
  export POSTGRES_USERNAME="<username>"
  export POSTGRES_PASSWORD="<password>"
  export POSTGRES_HOST="<host_address>"
```

Optional settings for PostgreSQL:

```sh
  export POSTGRES_PORT=<port>
  
  # For TLS connection
  export POSTGRES_SSL_CA="<ssl_ca>"
  export POSTGRES_SSL_CERT="<ssl_cert>"
  export POSTGRES_SSL_KEY="<ssl_key>"
  export POSTGRES_SSL_VERIFY_CERT=<True|False>
```

```shell
.use database-name
```

2. Import your Postgres database.

```shell
.import postgres <database> <source_table> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```

</fragment>

<fragment slot="panel.sqlite">
<slot name="SQLite" />

1. Select a SQL Database database.

```shell
.use database-name
```

2. Import your SQLite database.

```shell
.import sqlite <database> <source_table> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```

</fragment>
<fragment slot="panel.turso">
<slot name="Turso" />

Use the following commands to set enviroment variables with your Turso credentials:

```sh
 export TURSO_DATABASE_URL=<https://<db_name>-<organization>.turso.io
 export TURSO_AUTH_TOKEN=<token>
```

 Optional settings for Turso:
```sh
  export TURSO_ENCRYPTION_KEY=<encryption_key>
```

1. Select a SQL Database database.

```shell
.use database-name
```

2. Import your Turso database.

```shell
.import turso <database> <source_table> <table_name>
```
To verify the creation of your table you can use:

```shell
.tables
```

</fragment>
</Tabs>

## Importing from an SQL File

To import data from an `.sql` file containing SQL `INSERT` commands, use the `.read` command within the SQL Database Shell. This will execute the SQL statements contained in the file and populate your database with the specified data.

```shell
.read <file_name>
```