MySQL plugin for the Egg.js framework, providing a convenient wrapper around @eggjs/rds (ali-rds). Version 5.0.0 requires Node >=18.0.0. It supports both single and multiple data sources, CRUD operations, and manual/automatic transaction management. The plugin extends the app and agent with mysql/mysqls instances, enabling straightforward SQL queries. Key differentiators: tight integration with Egg.js lifecycle, singleton pattern for multiple DB clients, and full TypeScript type definitions.
npm install egg-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures egg-mysql plugin with a single MySQL connection, then uses app.mysql to run a query returning the current time.
Upgrade Node.js to 18 or later, or pin egg-mysql to 4.x for older Node versions.
Update package references and ensure @eggjs/rds is installed (it is bundled with egg-mysql).
Use @eggjs/rds directly if you need a standalone MySQL client.
For single data source, use app.mysql. For multiple, use app.mysqls.get('db1').Add declare module 'egg' { interface Application { mysql: ... } } or import types from @eggjs/rds.Run `npm install egg-mysql --save` and ensure config/plugin.ts includes `exports.default = { mysql: { enable: true, package: 'egg-mysql' } };`If using multiple clients, access via app.mysqls.get('db1'). Otherwise, ensure config uses 'client' not 'clients'.Verify MYSQL_HOST and MYSQL_PORT in config or environment. Ensure MySQL server is running and firewall allows connection.