Sunday, October 25, 2026 4,350 lists 78,100 records on file
List your app or device

  1. Home
  2. Database Migration Tools
  3. sqlx-cli

sqlx-cli

What it is

sqlx-cli is a command line tool for managing databases and migrations in SQLx projects, with commands for creating or dropping the database named by a database URL. It can create, run, inspect, and revert migrations, including paired up and down scripts. For query macros, `cargo sqlx prepare` writes query metadata to a `.sqlx` directory. Once that metadata is checked into version control, builds can run without connecting to a database. The `--check` option returns a nonzero status when the stored metadata is out of date, making it useful in continuous integration. In a workspace with multiple crates using query macros, `--workspace` writes one `.sqlx` directory at the workspace root. Commands take their database URL from `--database-url`, `DATABASE_URL`, or a `.env` file in the current directory. Installation is documented through `cargo install sqlx-cli`, with options for database drivers and TLS backends. It supports PostgreSQL, MySQL, MariaDB, and SQLite, and is free and open source. MSSQL support was removed pending a driver rewrite.

For and against

For

  • Creates, runs, inspects, and reverts migrations
  • Prepares query metadata for offline builds
  • Checks stored metadata for CI use
  • Supports PostgreSQL, MySQL, MariaDB, and SQLite

Against

  • MSSQL support was removed
  • Commands require a database URL

The verdict

sqlx-cli brings database operations, migration management, and offline query preparation into one command line tool. Check its supported database drivers against your project needs, especially if you rely on MSSQL.

Who it suits

It suits Rust developers who use SQLx and need database, migration, or query-metadata commands. Teams maintaining query macros across multiple crates can prepare or check shared workspace metadata.

Plans and prices

sqlx-cli

Free

Database management · migrations · offline query metadata

Every plan, in full

On the record

CI check
`cargo sqlx prepare --check` exits with a nonzero status when cached metadata is outdated and is described as intended for continuous integration.github.com · read 11 Oct 2026
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.github.com · read 4 Oct 2026
Configuration
Commands require a database URL supplied through `--database-url`, the `DATABASE_URL` environment variable, or a `.env` file in the current working directory.github.com · read 4 Oct 2026
Connection configuration
Commands require a database URL supplied with `--database-url` or through `DATABASE_URL` in the environment or a `.env` file.github.com · read 11 Oct 2026
Database commands
The CLI can create and drop the database specified by `DATABASE_URL`.github.com · read 11 Oct 2026
Database management
The CLI can create and drop the database specified by `DATABASE_URL`.github.com · read 4 Oct 2026
Database support
Its default installation supports the databases supported by SQLx; installation options include PostgreSQL-only and SQLite-specific configurations.github.com · read 11 Oct 2026
Installation
The CLI can be installed with `cargo install sqlx-cli`.github.com · read 11 Oct 2026
License
The SQLx repository lists Apache-2.0 and MIT license files.github.com · read 11 Oct 2026
Migrations
It can create migration files, run pending migrations, show migration status, and revert reversible migrations.github.com · read 11 Oct 2026
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`.github.com · read 11 Oct 2026
Notable limitation
The project README says MSSQL support was removed pending a full rewrite of the driver as part of the SQLx Pro initiative.github.com · read 4 Oct 2026
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.github.com · read 11 Oct 2026
Offline mode setting
Setting `SQLX_OFFLINE=true` forces offline builds when a `DATABASE_URL` variable or `.env` file is present.github.com · read 4 Oct 2026
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.github.com · read 4 Oct 2026
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.github.com · read 11 Oct 2026
Purpose
SQLx CLI is a command-line utility for managing databases and migrations and enabling offline mode for SQLx query macros.github.com · read 11 Oct 2026
Query metadata scope
For workspaces with multiple crates using query macros, `cargo sqlx prepare --workspace` generates a single `.sqlx` directory at the workspace root.github.com · read 4 Oct 2026

The review

sqlx-cli is a command-line utility for SQLx database and migration workflows, best suited to Rust developers using PostgreSQL, MySQL, MariaDB, or SQLite. Its focused migration and offline-query tools make it a strong fit for SQLx projects, while MSSQL users should choose another option.

Overview

SQLx is an asynchronous, pure-Rust SQL toolkit with compile-time checked queries. The CLI adds commands to create or drop the database named by DATABASE_URL, manage migrations, and prepare query metadata for offline builds. It is open source under either the Apache-2.0 or MIT license, at the user's choice.

Commands require a connection supplied with --database-url, through the DATABASE_URL environment variable, or in a .env file in the current working directory. That is predictable for local work, but CI and shared environments must deliberately provide and protect the connection settings.

Key features

Database and migration commands

sqlx-cli can create and drop the configured database, then create, run, inspect, or revert migrations. Paired up and down SQL scripts define both a change and its rollback, and rollback support is useful when a deployment needs a controlled reversal. Keeping database lifecycle and migration commands beside SQLx query tooling suits projects that want one Rust-oriented workflow; teams seeking a broader, database-agnostic change-management system may prefer another tool.

Offline query metadata

cargo sqlx prepare stores query metadata in a .sqlx directory. Once that directory is committed to version control, builds can proceed without an active database connection, which is valuable for reproducible builds and environments where database access is restricted. In a workspace with several crates using query macros, --workspace creates one metadata directory at the workspace root instead of separate crate-level copies.

CI validation

cargo sqlx prepare --check returns a nonzero status when saved metadata is stale. That makes drift a visible CI failure rather than a late build surprise, and the project specifically positions the command for continuous integration. Setting SQLX_OFFLINE=true forces offline builds when a database URL or .env file is present, giving teams an explicit switch for disconnected builds.

Drivers and installation

The documented installation command is cargo install sqlx-cli, with feature options for selecting database drivers and TLS backends. PostgreSQL, MySQL, MariaDB, and SQLite are listed by SQLx; options include native TLS, vendored OpenSSL, and Rustls. Non-TLS MySQL or MariaDB connections using RSA authentication require the mysql-rsa feature. MSSQL support was removed pending a full driver rewrite, so SQL Server projects are outside the CLI's current fit.

Pricing

The sqlx-cli plan costs free. It includes database management, migrations, and offline query metadata, with no paid tier, seat charge, quota, or trial term described. Open-source licensing and self-hosted command-line use make it suitable for individual developers and teams that can operate their own database and CI infrastructure. The trade-off is that there is no hosted service or commercial plan supplying managed operations.

Platforms

sqlx-cli supports Linux, macOS, and Windows. It is a self-hosted command-line tool installed through Cargo, so teams control installation, database credentials, migration files, and CI execution rather than using a web console.

Who it's for

Choose sqlx-cli when your application already uses SQLx and you want database creation, SQL migrations, compile-time query metadata, and CI freshness checks in one Rust-centered workflow. It is especially appropriate for teams comfortable committing the .sqlx directory and managing connection configuration themselves. It is a poor fit for MSSQL projects, and less compelling when you need a vendor-neutral migration platform or hosted governance features.

Pros and cons

  • Pro: Free and open source under Apache-2.0 or MIT, making the complete command-line workflow accessible without subscription costs.
  • Pro: Up, down, inspection, and rollback migration commands cover the core lifecycle instead of stopping at deployment.
  • Pro: Offline metadata and a CI check reduce dependence on live databases during builds and expose stale query definitions early.
  • Con: MSSQL support is unavailable pending a driver rewrite, excluding SQL Server workloads.
  • Con: Every command depends on an explicitly supplied database URL, so credential and environment setup remains the team's responsibility.
  • Con: Driver and TLS choices are installation features, and MySQL RSA authentication may require an extra feature, adding setup decisions.

Alternatives

Database Migration Tools is the broader starting point when you want to compare migration software by category.

Doctrine Migrations is a free, MIT-licensed PHP library installed with Composer or as a PHAR, making it the more natural choice for PHP applications.

Skeema fits teams wanting schema objects, stored procedures and functions, and linter checks across Linux, macOS, and Windows; its Community plan is free, while Plus costs $124 a month.

Sqitch is a free database change-management application with a permissive license that also allows modification, distribution, and sale.

Atlas is the alternative when an open-core migration engine and optional advanced features are preferable.

Bytebase Enterprise suits teams seeking web or API-based governance, with a free Community plan for up to 20 users and 10 database instances and a Pro plan at $20 a month per user.

db-migrate is a free MIT-licensed Node.js option for teams already standardizing on Node.js 24 or newer and installing database drivers separately.

dbmate is a free, open-source migration tool for teams that want a cross-platform utility without a stated paid SaaS upsell.

FluentMigrator is a free Apache-2.0 framework distributed through NuGet, with provider packages selected separately.

Verdict

sqlx-cli is a strong recommendation for Rust teams already committed to SQLx: it combines practical migration controls with offline query preparation and a meaningful CI freshness check at no cost. Look elsewhere if you require MSSQL, hosted administration, or a migration system designed independently of SQLx and Rust.

Alternatives to sqlx-cli

Every alternative, ranked