# How to use SQL Database Shell commands

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

SQL Database Shell provides a command-line interface to manage and interact with your SQL Database databases. Beyond executing SQL queries, it offers a comprehensive set of commands for database administration and configuration.

This guide covers the available commands for interacting with the SQL Database service and managing environment variables.

## SQL Database Shell commands

### help

Shows information about the available commands or a specific command.

```sh
EdgeSQL> help
```
****
Example:

```sh
EdgeSQL> help .dump
```

### .databases

Lists all databases.

```sh
EdgeSQL> .databases
```

### .use

Switches to a specific database.

```sh
EdgeSQL> .use <database-name>
```

### .tables

Lists all tables in the database.

```sh
EdgeSQL> .tables
```

### .schema

Describes the schema of a specific table.

```sh
EdgeSQL> .schema <table-name>
```

### .dbinfo

Retrieves information about the current database.

```sh
EdgeSQL> .dbinfo
```

### .read

Loads and executes SQL queries from a file.

```sh
EdgeSQL> .read <file_path>
```

### .create

Creates a new database.

```sh
EdgeSQL> .create <database-name>
```

### .destroy

Destroys a specific database.

```sh
EdgeSQL> .destroy <database-name>
```

### .output

Sets the output destination. Pass `stdout` as parameter to output to the console or inform a **file path** to define it as the output destination.

```sh
EdgeSQL> .output stdout
```

Example using a file as destination:

```sh
EdgeSQL> .output /file.csv
```

### .dump

Renders the table structure as SQL. After running the `output` command and setting the output to a file, the `dump` command will save the output to the selected file.

```sh
EdgeSQL> .dump <table-name>
```

You can pass the options `--schema-only` or `--data-only` to optionally render only the schema or the data of the table.

Example:

```sh
EdgeSQL> .dump --schema-only <table-name>
```

### .mode

Sets the output mode. You can choose one of the following options:

-  excel
-  tabular
-  csv
-  json
-  html
-  markdown
-  raw

Example:

```sh
EdgeSQL> .mode tabular
```

### .import

Imports data from an external source into the table. You can import data from a file or from a MySQL, Postgres, Kaggle or Turso database.

```sh
EdgeSQL> .import <params> <table-name>
```

By running the `help` command you can get a list of the possible parameters for importing data:

```sh
EdgeSQL> help .import
```

You will receive a response similar to this:

```sh
.import: Import data from file files, Kaggle datasets, or databases into a database table.

    Args:
        arg (str): The import command and its arguments.

    Command Formats:
        .import file <csv|xlsx> <file_path> <table_name>: Import data from a file CSV or Excel file.
        .import kaggle <dataset> <data_name> <table_name>: Import data from a Kaggle dataset.
        .import mysql <database> <source_table> <table_name>: Import data from a MySQL database table.
        .import postgres <database> <source_table> <table_name>: Import data from PostgreSQL database table.
        .import turso <database> <source_table> <table_name>: Import data from Turso database.

    Examples:
        .import file csv /path/to/file.csv my_table
        .import kaggle joonasyoon/google-doodles list.csv list
        .import mysql mydb_name source_table_name my_table
        .import turso <database> <source_table> <table_name>
```

### .dbsize

Gets the size of the current database in MB.

```sh
EdgeSQL> .dbsize
```

### .exit

Exits the EdgeSQL Shell.

```sh
EdgeSQL> .exit
```

## Environment variables

When using the SQL Database Shell to import data from external sources, you can send the credentials and tokens as environment variables byt using the `export` command. This command is also used for setting your Azion **personal token**.

### Personal token

You can send your **personal token** as an environment variable in SQL Database Shell.

```sh
 export AZION_TOKEN="<your_auth_token_here>"
```

### Kaggle credentials

Use the following commands to set your Kaggle credentials:

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

### MySQL credentials

Use the following commands to set 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>
```

### PostgreSQL credentials

Use the following commands to set 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>
```

### Turso credentials

Use the following commands to set 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>
```

<DocButton href="/en/documentation/products/store/sql/install-edge-sql-shell" label="Go to SQL Database Shell installation guide" kind="secondary" size="medium" />