A wrapper for mysql2 that manages MySQL connections in serverless environments like AWS Lambda, Google Cloud Functions, and Azure Functions. Current stable version is 2.1.0, released regularly. It prevents connection exhaustion by monitoring and limiting concurrent connections, cleaning up zombie connections, and retrying with exponential backoff. Differentiators include built-in async/await support, simplified transactions, and optional SQL query logging for debugging. Ships TypeScript types and works with any standards-based MySQL server including RDS, Aurora, and Aurora Serverless.
npm install serverless-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes the connection manager with environment variables, runs a parameterized query, and cleans up resources.
Initialize `const mysql = require('serverless-mysql')({...})` at module scope, not inside the handler.Always call `await mysql.end()` after finishing all queries in a handler invocation.
Use `mysql.end()` instead of deprecated `mysql.quit()`. Update to Node 10+.
Replace `mysql.quit()` with `mysql.end()`.
Check for `sql` property in results if you iterate over keys, or disable the option if not needed.
Ensure each handler invocation initializes the module once at global scope and only calls `mysql.end()` once per invocation.
Use `const mysql = require('serverless-mysql')({...})` with parentheses, not just `require('serverless-mysql')`.Increase idle timeout or use `mysql.end()` to release connections promptly. Adjust `maxRetries` and `backoff` options.
Call `mysql.end()` after each request, reduce `maxConcurrentQueries` option, or increase MySQL max_connections. Ensure initialization is outside the handler.