{"record":{"id":"3d8fa0eee94bb830","repo":"windmill-labs/windmill","slug":"error-executing-query","errorCode":null,"errorMessage":"Error executing query: {:?}","messagePattern":"Error executing query: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-worker/src/mysql_executor.rs","lineNumber":92,"sourceCode":"    };\n\n    let result_f = async move {\n        if skip_collect {\n            conn.lock()\n                .await\n                .exec_drop(query, statement_values)\n                .await\n                .map_err(to_anyhow)?;\n\n            Ok(vec![])\n        } else if let Some(ref s3) = s3 {\n            let query = query.to_string();\n            let rows_stream = async_stream::stream! {\n                let mut conn = conn.lock().await;\n                let mut result = match conn.exec_iter(query, statement_values).await.map_err(to_anyhow) {\n                    Ok(result) => result,\n                    Err(e) => {\n                        yield Err(anyhow!(\"Error executing query: {:?}\", e));\n                        return;\n                    }\n                };\n                loop {\n                    let row = result.next().await;\n                    match row {\n                        Ok(Some(row)) => {\n                            yield Ok(convert_row_to_value(row));\n                        }\n                        Ok(None) => {\n                            break;\n                        }\n                        Err(e) => {\n                            yield Err(anyhow!(\"Error fetching row: {:?}\", e));\n                            return;\n                        }\n                    }\n                }","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/mysql_executor.rs#L74-L110","documentation":"The MySQL executor streams query results; `conn.exec_iter(query, statement_values)` failed, so the stream yields this error instead of rows. It wraps the mysql_async error with debug formatting. The query never started executing (as opposed to failing mid-row, which is error 1046).","triggerScenarios":"`do_mysql_inner` executing a MySQL script resource query when the connection is dead/stale, SQL syntax is invalid, the referenced table/column doesn't exist, insufficient privileges, or a prepared-statement parameter type mismatches the column.","commonSituations":"MySQL server restarted between connection-pool creation and query (server has gone away); typos or schema drift in the SQL; user lacking SELECT on the target table; wrong port/db name in the MySQL resource; timeout `wait_timeout` reaping idle pooled connections.","solutions":["Read the wrapped mysql_async error for the SQLSTATE code (e.g. 1146 table missing, 1064 syntax, 2006 gone away).","Fix the SQL in the script, or align it with the current schema.","Check the MySQL resource (host, port, user, password, database) and test connectivity.","If 'server has gone away', increase `wait_timeout`/`max_allowed_packet` on MySQL or enable connection ping/reconnect in the pool config.","Grant the user the needed privileges on the target tables."],"exampleFix":"// before\nSELECT form unexisting_table;\n// after\nSELECT * FROM existing_table;  -- verify with SHOW TABLES first","handlingStrategy":"try-catch","validationCode":"// validate SQL and connectivity before executing in the job\n// 1. test connection: mysql -h $HOST -P $PORT -u $USER -p -e 'select 1' $DB\n// 2. validate SQL: mysql ... -e \"PREPARE stmt FROM 'SELECT * FROM my_table LIMIT 1'\"","typeGuard":null,"tryCatchPattern":"match result {\n    Ok(rows) => rows,\n    Err(e) => {\n        // inspect SQLSTATE to branch: 1064 syntax, 1146 missing table, 2006 gone away\n        return Err(anyhow!(\"mysql query failed: {e:?}\"));\n    }\n}","preventionTips":["Test the MySQL resource (host/port/creds) before wiring it into scripts","Validate SQL against the real schema; watch for schema drift","Enable pool connection ping or lower idle timeouts to avoid 'gone away' errors","Grant the resource user only the privileges it needs — and at least those"],"tags":["mysql","database","query","sql"],"backgroundTag":"sql-query-execution-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}