mysql
Enterprise MySQL & MariaDB production rules — query safety, connection pooling, and strict schema configurations.
MySQL / MariaDB Production Standards
MySQL and MariaDB are powerful relationship-driven databases, but AI agents MUST adhere to these strict behavioral boundaries when executing queries, utilizing the mysql-mcp server, or generating application code.
1. Query Safety & Execution Rules
- Absolute Parameterization: You MUST ALWAYS use parameterized queries (
?). Under zero circumstances are you permitted to string-interpolate or concatenate variables into a raw SQL string. This is to enforce strict SQL-injection prevention. - Guarded Reads: Every top-level
SELECTstatement MUST contain aLIMITclause unless explicitly overridden by the user. Do not execute unboundedSELECT * FROM table;queries. - Safe Destructive Ops:
DELETEandUPDATEqueries MUST include aWHEREclause. Never execute these operations without a targeted identifier. - Action Scoping: Limit operations to single-statements. Do not stack multiple statements (
query1; query2;) in a single payload unless executing a batch migration.
2. Connections & Transactions
- Connection Pooling: Always assume and design for connection pooling. Code evaluating database connections should handle acquiring from and releasing to a pool, avoiding connection leaks.
- Data Mutability Scopes: Whenever executing writes spanning across multiple tables (e.g., inserts requiring foreign key links), they MUST be wrapped in a transaction block:
START TRANSACTION; ... COMMIT;with robustROLLBACKlogic in thecatchblock.
3. Strict Schema Configurations
- Mode Enforcement: Ensure
sql_modeincludesSTRICT_TRANS_TABLESandONLY_FULL_GROUP_BY. AI agents must not disable these modes to bypass errors; you must rewrite yourGROUP BYlogic to be strictly compliant. - Foreign Keys: Explicitly define
FOREIGN KEYconstraints duringCREATE TABLEunless specifically orchestrating a Vitess/PlanetScale sharded environment where declarative FKs are explicitly forbidden by the user context.
4. Ecosystem & Diagnostics
- Error Handling: When intercepting connection drops or authentication failures (e.g., ER_ACCESS_DENIED_ERROR), instruct the user to verify their
.envconfigurations (MYSQL_URL,MYSQL_HOST, etc.). Do not hallucinate database names. - Using MCP: If the
mysql-mcpserver is attached, prefer utilizing its formal 227+ structured tools over executing raw Bash CLI scripts (mysql -h ...) to guarantee payload optimizations and schema intelligence.