dolt-sql
Execute SQL queries against Dolt databases
TLDR
Run a single query
List all saved queries
SYNOPSIS
dolt sql [flags]
PARAMETERS
-q, --query
Executes the specified SQL query_string and exits.
-f, --filename
Executes SQL commands from the given file_path.
-H, --host
Specifies the hostname of the Dolt SQL server to connect to. Default is 'localhost'.
-P, --port
Specifies the port number of the Dolt SQL server to connect to. Default is '3306'.
-u, --user
Specifies the username for connecting to a Dolt SQL server.
-p, --password
Specifies the password for connecting to a Dolt SQL server. If not provided for a user requiring one, it will be prompted.
--read-only
Opens the Dolt database in read-only mode, preventing any modifications.
--branch
Specifies the branch to query or operate on. Useful when working with different data versions.
--format
Sets the output format for query results (e.g., csv, json, tabular, html, xml, json-array, json-table, vertical). Default is 'tabular' for interactive mode.
DESCRIPTION
The dolt sql command provides a command-line interface (CLI) for interacting with the SQL engine of a Dolt database. Dolt is a unique database that combines the features of a relational database with the version control capabilities of Git. Using dolt sql, users can execute standard SQL queries directly against their Dolt repositories.
It supports two primary modes of operation: interactive shell and single query execution. In interactive mode, it provides a MySQL-compatible SQL shell, allowing users to type and execute queries sequentially. For single query execution, the --query (-q) flag is used to pass a SQL statement directly, making it suitable for scripting. Additionally, queries can be read from a file using the --filename (-f) flag.
Beyond local repository interaction, dolt sql can also act as a client to connect to a running dolt sql-server instance, enabling remote access and multi-user environments. Its aim is to provide a familiar SQL experience while leveraging Dolt's powerful data versioning, branching, merging, and diffing capabilities.
CAVEATS
While dolt sql strives for MySQL compatibility, it is not 100% identical. Users might encounter minor differences in supported functions, data types, or specific SQL syntax. Performance characteristics may also differ from traditional RDBMS due to Dolt's underlying Git-like versioning architecture.
INTERACTIVE MODE
When run without the --query or --filename flags, dolt sql enters an interactive SQL shell. This shell provides a familiar experience similar to the MySQL client, allowing users to type and execute multiple SQL statements sequentially, manage sessions, and see query results directly.
LOCAL VS. SERVER CONNECTION
By default, dolt sql operates on the Dolt repository in the current directory (or one specified by --data-dir). However, it can also function as a client to connect to a remotely running dolt sql-server instance, using the --host, --port, --user, and --password flags. This distinction allows for both standalone local development and multi-user server-based deployments.
HISTORY
Dolt was developed by DoltHub (originally Liquidata) with the vision of bringing Git-like version control to data. The dolt sql command has been a foundational component of the Dolt ecosystem since its inception, enabling users to interact with their versioned data using familiar SQL syntax. Its evolution has focused on expanding SQL compatibility, enhancing performance, and integrating seamlessly with Dolt's unique branching, merging, and diffing capabilities.