SeaQL/sea-orm · error
Not MySQL Connection
Error message
Not MySQL Connection
What it means
get_mysql_connection_pool() hands out the underlying sqlx::MySqlPool so users can run raw sqlx. It panics when the DatabaseConnection wraps anything other than SqlxMySqlPoolConnection (Postgres, SQLite, mock, proxy, rusqlite, or Disconnected).
Source
Thrown at sea-orm-sync/src/database/db_connection.rs:782
// Nothing to cleanup, we just consume the `DatabaseConnection`
Ok(())
}
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
}
}
}
impl DatabaseConnection {
/// Get [sqlx::MySqlPool]
///
/// # Panics
///
/// Panics if [DbConn] is not a MySQL connection.
#[cfg(feature = "sqlx-mysql")]
pub fn get_mysql_connection_pool(&self) -> &sqlx::MySqlPool {
match &self.inner {
DatabaseConnectionType::SqlxMySqlPoolConnection(conn) => &conn.pool,
_ => panic!("Not MySQL Connection"),
}
}
/// Get [sqlx::PgPool]
///
/// # Panics
///
/// Panics if [DbConn] is not a Postgres connection.
#[cfg(feature = "sqlx-postgres")]
pub fn get_postgres_connection_pool(&self) -> &sqlx::PgPool {
match &self.inner {
DatabaseConnectionType::SqlxPostgresPoolConnection(conn) => &conn.pool,
_ => panic!("Not Postgres Connection"),
}
}
/// Get [sqlx::SqlitePool]
///View on GitHub (pinned to e29bcd1b41)
Solutions
- Connect with a mysql:// URL (with the sqlx-mysql feature enabled) before requesting the pool
- Match on get_database_backend() == DbBackend::MySql before unwrapping the pool
- Route raw-pool access behind a helper that takes a backend-specific connection type
Example fix
// before
let conn = Database::connect("postgres://...").await?;
let pool = conn.get_mysql_connection_pool(); // panics
// after
let conn = Database::connect("mysql://...").await?;
if conn.get_database_backend() == DbBackend::MySql {
let pool = conn.get_mysql_connection_pool();
} Defensive patterns
Strategy: validation
Validate before calling
assert_eq!(conn.get_database_backend(), DbBackend::MySql, "raw pool access requires a MySQL connection"); let pool = conn.get_mysql_connection_pool();
Type guard
fn as_mysql_pool(conn: &DatabaseConnection) -> Option<&sqlx::MySqlPool> {
(conn.get_database_backend() == DbBackend::MySql).then(|| conn.get_mysql_connection_pool())
} Try / catch
let pool = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.get_mysql_connection_pool()));
if pool.is_err() { return Err(anyhow!("not a MySQL connection")); } Prevention
- Validate DATABASE_URL scheme (mysql://) at startup when using MySQL-specific APIs
- Gate backend-specific code behind cfg(feature = "sqlx-mysql") and backend checks
- Keep raw-pool escapes in one module that asserts the backend once
When it happens
Trigger: Calling get_mysql_connection_pool() on a connection created for another backend (e.g. postgres:// or sqlite:// URL), on a MockDatabase connection, or on a Disconnected connection.
Common situations: Backend selected from an environment/config URL that is not MySQL while code assumes MySQL; test code using MockDatabase then trying to fetch the raw pool; feature sqlx-mysql not enabled so MySQL was never connectable.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Not Postgres Connection
- Not SQLite Connection
- Not MySQL Connection
- Failed to get boolean
- Failed to get unsigned tiny integer
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/2897bc99cf944126.
Report an issue: GitHub.