{"record":{"id":"8fd5abf5c53735cc","repo":"crewAIInc/crewAI","slug":"mysql-database-error-e","errorCode":null,"errorMessage":"MySQL database error: {e}","messagePattern":"MySQL database error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/rag/loaders/mysql_loader.py","lineNumber":100,"sourceCode":"                    content = \"\\n\".join(text_parts)\n\n                    if len(content) > 100000:\n                        content = content[:100000] + \"\\n\\n[Content truncated...]\"\n\n                    return LoaderResult(\n                        content=content,\n                        metadata={\n                            \"source\": query,\n                            \"database\": connection_params[\"database\"],\n                            \"row_count\": len(rows),\n                            \"columns\": columns,\n                        },\n                        doc_id=self.generate_doc_id(source_ref=query, content=content),\n                    )\n            finally:\n                connection.close()\n        except Error as e:\n            raise ValueError(f\"MySQL database error: {e}\") from e\n        except Exception as e:\n            raise ValueError(f\"Failed to load data from MySQL: {e}\") from e\n","sourceCodeStart":82,"sourceCodeEnd":103,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/rag/loaders/mysql_loader.py#L82-L103","documentation":"Raised by MySQLLoader.load() when the database interaction raises pymysql.Error — the except Error clause catches connection failures (bad credentials ER_ACCESS_DENIED, unknown host, unreachable server, unknown table/column in the executed query) raised by connect() or cursor.execute(query). The original MySQL error number/message is included and chained.","triggerScenarios":"Wrong username/password (1045 Access denied); MySQL server down or host/port blocked by firewall (2003 Can't connect); executing a query with a typo'd table or column (1146/1054); querying a table in a different schema than the URI's database; packet or auth plugin incompatibilities (caching_sha2_password with old clients).","commonSituations":"Rotated DB credentials not propagated to the agent config; network policies blocking the DB port from containerized runs; query strings built from user input with table names that don't exist; MySQL 8 auth plugin issues with outdated pymysql; dev/prod schema drift.","solutions":["Test the same URI and query with a plain client: mysql --host=... -u ... -p -e 'SELECT 1' to isolate credentials vs network vs query errors.","Fix credentials/host in the db_uri; ensure the DB server accepts connections from where the loader runs.","Run the exact query manually against the URI's database to catch SQL typos before ingestion.","Upgrade pymysql if you see authentication plugin errors against MySQL 8."],"exampleFix":"# before\nresult = MySQLLoader().load(SourceContent('SELECT * FROM usr'), metadata={'db_uri': uri})  # 1146\n\n# after\nresult = MySQLLoader().load(SourceContent('SELECT * FROM users'), metadata={'db_uri': uri})","handlingStrategy":"try-catch","validationCode":"import pymysql\\n\\ndef can_connect(uri_check: dict) -> bool:\\n    try:\\n        pymysql.connect(**uri_check, connect_timeout=5)\\n        return True\\n    except pymysql.Error:\\n        return False","typeGuard":null,"tryCatchPattern":"try:\\n    result = MySQLLoader().load(src, metadata={'db_uri': uri})\\nexcept ValueError as e:\\n    if 'MySQL database error' in str(e):\\n        classify_and_alert(str(e))  # credentials vs network vs SQL syntax\\n    raise","preventionTips":["Smoke-test connectivity and the exact SQL before batch ingestion.","Pull credentials from a secrets manager with rotation awareness.","Restrict queries to known-good table names, not free user text."],"tags":["mysql","database","sql","network"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}