{"record":{"id":"eb37a5db0cbc1a15","repo":"transact-rs/sqlx","slug":"failed-to-parse-database-url","errorCode":null,"errorMessage":"failed to parse DATABASE_URL","messagePattern":"failed to parse DATABASE_URL","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sqlx-mysql/src/testing/mod.rs","lineNumber":102,"sourceCode":"        }\n\n        query.push(\")\").build().execute(&mut conn).await?;\n\n        let _ = conn.close().await;\n        Ok(Some(delete_db_names.len()))\n    }\n\n    async fn snapshot(_conn: &mut Self::Connection) -> Result<FixtureSnapshot<Self>, Error> {\n        // TODO: I want to get the testing feature out the door so this will have to wait,\n        // but I'm keeping the code around for now because I plan to come back to it.\n        todo!()\n    }\n}\n\nasync fn test_context(args: &TestArgs) -> Result<TestContext<MySql>, Error> {\n    let url = dotenvy::var(\"DATABASE_URL\").expect(\"DATABASE_URL must be set\");\n\n    let master_opts = MySqlConnectOptions::from_str(&url).expect(\"failed to parse DATABASE_URL\");\n\n    let pool = PoolOptions::new()\n        // MySql's normal connection limit is 150 plus 1 superuser connection\n        // We don't want to use the whole cap and there may be fuzziness here due to\n        // concurrently running tests anyway.\n        .max_connections(20)\n        // Immediately close master connections. Tokio's I/O streams don't like hopping runtimes.\n        .after_release(|_conn, _| Box::pin(async move { Ok(false) }))\n        .connect_lazy_with(master_opts);\n\n    let master_pool = match once_lock_try_insert_polyfill(&MASTER_POOL, pool) {\n        Ok(inserted) => inserted,\n        Err((existing, pool)) => {\n            // Sanity checks.\n            assert_eq!(\n                existing.connect_options().host,\n                pool.connect_options().host,\n                \"DATABASE_URL changed at runtime, host differs\"","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-mysql/src/testing/mod.rs#L84-L120","documentation":"After reading DATABASE_URL, `test_context` parses it with `MySqlConnectOptions::from_str(..).expect(..)`. The panic means the string exists but is not a valid MySQL connection URL (bad scheme, malformed userinfo, unparseable options).","triggerScenarios":"`#[sqlx::test]` with DATABASE_URL set to a non-MySQL URL (e.g. `postgres://`), an empty string, missing `mysql://` scheme, or invalid URL syntax/options query string.","commonSituations":"Copy-pasting a Postgres URL into a MySQL test setup; typos like `mysql:/host` or unescaped special characters (`@`, `#`, `%`) in the password; leftover placeholder `DATABASE_URL=` (empty).","solutions":["Use a properly formed URL: `mysql://user:password@host:3306/dbname`.","Percent-encode special characters in the password (e.g. `@` -> `%40`).","Ensure the scheme is `mysql://`, matching the MySQL test harness.","Print/inspect DATABASE_URL (redacting credentials) to spot truncation or quoting issues in .env."],"exampleFix":"// before (.env)\nDATABASE_URL=postgres://root:pw@localhost/db\n// after\nDATABASE_URL=mysql://root:pw%40special@localhost:3306/mysql","handlingStrategy":"validation","validationCode":"// Parse-check DATABASE_URL before tests:\nlet url = dotenvy::var(\"DATABASE_URL\").expect(\"DATABASE_URL must be set\");\nassert!(url.starts_with(\"mysql://\"), \"MySQL tests need mysql:// scheme, got: {:?}\", &url[..url.len().min(12)]);\nlet _opts = sqlx::mysql::MySqlConnectOptions::from_str(&url)\n    .expect(\"DATABASE_URL is not a valid MySQL URL\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Percent-encode special characters in passwords","Match the scheme to the driver: mysql:// for MySQL tests","Validate .env values in CI before running the suite"],"tags":["sqlx","mysql","testing","url-parse","panic"],"backgroundTag":"invalid-database-url","analyzedSha":"03af8bcc5711a1935580a54bea249c219a0c217d","analyzedAt":"2026-09-03T15:01:28.752Z","contentChangedAt":"2026-09-03T15:01:28.752Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}