How to import data to SQL Database
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.
-
Database Setup: You need to have a database created. To create a new database within SQL Database using the Shell, use the command:
.create <database-name>Importing Data with SQL Database Shell
- Select a SQL Database database.
.use database-name- Import your file.
.import file <csv|xlsx> <file_path> <table_name>To verify the creation of your table you can use:
.tables- Select a SQL Database database.
.use database-name- Import your SQLite database.
.import sqlite <database> <source_table> <table_name>To verify the creation of your table you can use:
.tables- Select a SQL Database database.
.use database-name- Import your kaggle database.
Use the following commands to set enviroment variables with your Kaggle credentials:
export KAGGLE_USERNAME="<username>" export KAGGLE_KEY="<kaggle_api_key>".import kaggle <dataset> <data_name> <table_name>To verify the creation of your table you can use:
.tablesUse the following commands to set enviroment variables with your MySQL credentials:
export MYSQL_USERNAME="<username>" export MYSQL_PASSWORD="<password>" export MYSQL_HOST="<host_address>"Optional settings for MySQL:
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>- Select a SQL Database database.
.use database-name- Import your MySQL database.
.import mysql <database> <source_table> <table_name>To verify the creation of your table you can use:
.tables- Select a SQL Database database.
Use the following commands to set enviroment variables with your PostgreSQL credentials:
export POSTGRES_USERNAME="<username>" export POSTGRES_PASSWORD="<password>" export POSTGRES_HOST="<host_address>"Optional settings for PostgreSQL:
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>.use database-name- Import your Postgres database.
.import postgres <database> <source_table> <table_name>To verify the creation of your table you can use:
.tablesUse the following commands to set enviroment variables with your Turso credentials:
export TURSO_DATABASE_URL=<https://<db_name>-<organization>.turso.io export TURSO_AUTH_TOKEN=<token>Optional settings for Turso:
export TURSO_ENCRYPTION_KEY=<encryption_key>- Select a SQL Database database.
.use database-name- Import your Turso database.
.import turso <database> <source_table> <table_name>To verify the creation of your table you can use:
.tablesImporting 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.
.read <file_name>