{"record":{"id":"3cf7e64877570a8d","repo":"louislam/uptime-kuma","slug":"database-connection-query-failed-error-message-3cf7e6","errorCode":null,"errorMessage":"Database connection/query failed: ${error.message}","messagePattern":"Database connection/query failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/mysql.js","lineNumber":60,"sourceCode":"                    throw new Error(`Query result did not meet the specified conditions (${result})`);\n                }\n\n                heartbeat.status = UP;\n                heartbeat.msg = \"Query did meet specified conditions\";\n            } else {\n                // Backwards compatible: just check connection and return row count\n                const result = await this.mysqlQuery(monitor.databaseConnectionString, query, password);\n                heartbeat.ping = dayjs().valueOf() - startTime;\n                heartbeat.status = UP;\n                heartbeat.msg = result;\n            }\n        } catch (error) {\n            heartbeat.ping = dayjs().valueOf() - startTime;\n            // Re-throw condition errors as-is, wrap database errors\n            if (error.message.includes(\"did not meet the specified conditions\")) {\n                throw error;\n            }\n            throw new Error(`Database connection/query failed: ${error.message}`);\n        }\n    }\n\n    /**\n     * Run a query on MySQL/MariaDB (backwards compatible - returns row count)\n     * @param {string} connectionString The database connection string\n     * @param {string} query The query to execute\n     * @param {string} password Optional password override\n     * @returns {Promise<string>} Row count message\n     */\n    mysqlQuery(connectionString, query, password = undefined) {\n        return new Promise((resolve, reject) => {\n            const connection = mysql.createConnection({\n                uri: connectionString,\n                password,\n            });\n\n            connection.on(\"error\", (err) => {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/mysql.js#L42-L78","documentation":"Catch-all wrapper in MysqlMonitorType.check: any error whose message does NOT contain 'did not meet the specified conditions' is re-thrown as 'Database connection/query failed: <original>'. This wraps connection, auth, TLS, timeout, and SQL syntax errors from the mysql driver callback/promise chain.","triggerScenarios":"mysqlQuery/mysqlQuerySingleValue rejects: ECONNREFUSED, ETIMEDOUT, ER_ACCESS_DENIED_ERROR, ER_PARSE_ERROR, PROTOCOL_CONNECTION_LOST, SSL handshake failures, or the single-value validation errors. The substring guard re-throws condition-mismatch messages unchanged and wraps everything else.","commonSituations":"Wrong host/port (default 3306); bind-address only on localhost; user host wildcard missing ('user'@'%'); caching_sha2_password auth requiring TLS; wrong database name; SQL syntax error; connection pool limits hit on the server.","solutions":["Connect with the mysql CLI from the Uptime Kuma host using the same DSN/credentials.","Verify the user is allowed from the monitor's IP (SELECT user, host FROM mysql.user) and that auth plugin is supported.","If TLS is required, add ssl options to the connection string / DSN.","Run the query standalone to surface parse/permission errors.","Confirm server max_connections / wait_timeout is not exhausting the monitor."],"exampleFix":"// before: mysql://u:p@10.0.0.5:3306/app   (caching_sha2_password needs TLS)\n// after:  mysql://u:p@10.0.0.5:3306/app?ssl={'rejectUnauthorized':true}","handlingStrategy":"retry","validationCode":"function canConnect(dsn, ms=2000) {\n  const m = dsn.match(/mysql:\\/\\/([^:@\\/]+)(?::[^@]*)?@([^:\\/]+):(\\d+)/);\n  const [, , host, port] = m ? m : [,,'',3306]; return portOpen(host, Number(port||3306), ms);\n}","typeGuard":null,"tryCatchPattern":"async function withRetry(fn, retries=3, base=1000) {\n  for (let i=0;i<=retries;i++){ try { return await fn(); } catch(e){\n    if (/Database connection\\/query failed/.test(e.message) && i<retries) await sleep(base*2**i); else throw e; } }\n}","preventionTips":["Verify the user/host combo (SELECT user,host FROM mysql.user) and that the auth plugin is supported.","Add ssl options when the server requires TLS.","Wrap transient connection failures with bounded retry; alert on repeated failures."],"tags":["mysql","mariadb","database","connection","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}