SQLx supports connections to PostgreSQL, MySQL/MariaDB, and SQLite. You can open a single connection directly for simple use cases, or use a connection pool for applications that handle concurrent workloads. Both approaches use the sameDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/launchbadge/sqlx/llms.txt
Use this file to discover all available pages before exploring further.
Connection trait and share the same URL format conventions.
Connection URL formats
Each database driver parses a connection URL in a driver-specific format.- PostgreSQL
- MySQL / MariaDB
- SQLite
Both
postgres:// and postgresql:// are accepted scheme prefixes for PostgreSQL.Single connections
UseConnection::connect() to open a single database connection directly. Import the Connection trait to bring the method into scope.
Connection is not Clone, you must pass a mutable reference (&mut conn) to query finalizers.
The ConnectOptions trait
The ConnectOptions trait provides a typed, builder-style API for configuring a connection. Each database exposes its own implementation with driver-specific options.
| Database | Type |
|---|---|
| PostgreSQL | PgConnectOptions |
| MySQL | MySqlConnectOptions |
| SQLite | SqliteConnectOptions |
ConnectOptions values can be constructed by parsing a URL string or built programmatically:
Disabling statement logging
ConnectOptions exposes log_statements and disable_statement_logging methods for controlling how executed SQL is logged. This is useful in tests or when queries contain sensitive data:
Single connection vs. connection pool
Single connection
Best for scripts, CLI tools, tests, or anywhere you need direct control
over a single sequential flow of queries. Not
Clone; must be passed as
&mut conn.Connection pool
Best for web servers and long-lived applications where multiple tasks
issue queries concurrently.
Pool is Clone, Send, and Sync — share
it freely across tasks.