sqlx-cli
github.com
What it is
sqlx-cli is SQLx’s command-line utility for managing databases, migrations, and offline preparation for query macros. It can create or drop the database identified by a database URL, and create, run, inspect, or revert migrations, including paired up and down scripts. The `cargo sqlx prepare` command writes query metadata to a `.sqlx` directory. Once that metadata is checked into version control, builds can run without an active database connection. The `--check` option returns a nonzero status if the saved metadata is out of date, a behavior the project describes for continuous integration.
For workspaces whose crates use query macros, `cargo sqlx prepare --workspace` places one `.sqlx` directory at the workspace root. Commands accept the database URL through `--database-url`, the `DATABASE_URL` environment variable, or a `.env` file in the current directory. The project lists PostgreSQL, MySQL, MariaDB, and SQLite support, with installation options for database drivers and TLS backends. The CLI is free and open source under the user’s choice of Apache-2.0 or MIT license. The README notes that MSSQL support was removed pending a full driver rewrite.
Spec sheet
- Purpose
- SQLx CLI is a command-line utility for managing databases and migrations and enabling offline mode for SQLx query macros.Read 11 Oct 2026 · github.com
- Security
- The project README says SQLx forbids unsafe code unless the SQLite feature is enabled, where SQLite API calls use unsafe code that the maintainers welcome auditing and feedback on.Read 4 Oct 2026 · github.com
- Support
- The SQLx repository links to its FAQ and Discord community for questions.Read 11 Oct 2026 · github.com
- License
- The SQLx repository lists Apache-2.0 and MIT license files.Read 11 Oct 2026 · github.com
- CI check
- `cargo sqlx prepare --check` exits with a nonzero status when cached metadata is outdated and is described as intended for continuous integration.Read 11 Oct 2026 · github.com
- CI use
- `cargo sqlx prepare --check` exits with a nonzero status if the saved query metadata is out of date, and the README describes it as intended for Continuous Integration.Read 4 Oct 2026 · github.com
- Configuration
- Commands require a database URL supplied through `--database-url`, the `DATABASE_URL` environment variable, or a `.env` file in the current working directory.Read 4 Oct 2026 · github.com
- Connection configuration
- Commands require a database URL supplied with `--database-url` or through `DATABASE_URL` in the environment or a `.env` file.Read 11 Oct 2026 · github.com
- Database commands
- The CLI can create and drop the database specified by `DATABASE_URL`.Read 11 Oct 2026 · github.com
- Database management
- The CLI can create and drop the database specified by `DATABASE_URL`.Read 4 Oct 2026 · github.com
- Database support
- Its default installation supports the databases supported by SQLx; installation options include PostgreSQL-only and SQLite-specific configurations.Read 11 Oct 2026 · github.com
- Installation
- The CLI can be installed with `cargo install sqlx-cli`.Read 11 Oct 2026 · github.com
- Migrations
- It can create migration files, run pending migrations, show migration status, and revert reversible migrations.Read 11 Oct 2026 · github.com
- MySQL authentication limit
- The `mysql-rsa` feature is needed for non-TLS MySQL or MariaDB connections when the server requires RSA authentication using `caching_sha2_password` or `sha256_password`.Read 11 Oct 2026 · github.com
- Notable limitation
- The project README says MSSQL support was removed pending a full rewrite of the driver as part of the SQLx Pro initiative.Read 4 Oct 2026 · github.com
- Offline builds
- `cargo sqlx prepare` saves query metadata to `.sqlx`, allowing builds without an active database connection after that directory is checked into version control.Read 11 Oct 2026 · github.com
- Offline mode setting
- Setting `SQLX_OFFLINE=true` forces offline builds when a `DATABASE_URL` variable or `.env` file is present.Read 4 Oct 2026 · github.com
- Offline query preparation
- `cargo sqlx prepare` saves query metadata to `.sqlx`, allowing builds without an active database connection when that metadata is checked into version control.Read 4 Oct 2026 · github.com
- Project scope
- The SQLx project describes itself as an asynchronous, pure Rust SQL toolkit with compile-time checked queries and support for PostgreSQL, MySQL, and SQLite.Read 11 Oct 2026 · github.com
- Query metadata scope
- For workspaces with multiple crates using query macros, `cargo sqlx prepare --workspace` generates a single `.sqlx` directory at the workspace root.Read 4 Oct 2026 · github.com
- Support channel
- The project README directs users with questions to its FAQ and links to a Discord community.Read 4 Oct 2026 · github.com
- Supported databases
- The CLI installation instructions say it supports the databases supported by SQLx; the project lists PostgreSQL, MySQL, MariaDB, and SQLite.Read 4 Oct 2026 · github.com
- TLS options
- Installation options include native TLS, vendored OpenSSL, and Rustls configurations.Read 11 Oct 2026 · github.com
Plans and prices
Strong points and limits
Strong points
- Creates, runs, inspects, and reverts migrations
- Offline query metadata enables disconnected builds
- Metadata check detects outdated saved queries
- Supports PostgreSQL, MySQL, MariaDB, and SQLite
- Free and open source
Limits
- MSSQL support was removed
- Commands require a database URL
- Installation requires selecting drivers and TLS options
Who it suits
sqlx-cli suits Rust developers who need database migrations, query-macro metadata, or checks in CI. It is useful where the project’s supported databases and command-line setup fit the development environment.
Verdict
sqlx-cli covers database setup, migration work, and offline query-metadata workflows in one command-line tool. Its database support and URL configuration requirements should be checked against the project’s setup.
Where Specifiction places it
- Database Migration Tools#11 of 328.0