{"id":42731,"library":"express-mysql-pool","title":"express-mysql-pool","description":"Express middleware that provides MySQL connection pooling, automatically attaching a connection to each request and releasing it on response end. Version 1.0.3 (latest, no recent updates). Simple wrapper around mysql module's pool; focuses on request-scoped connections. Alternatives: express-mysql-connection (individual connections), mysql2/promise pool (modern).","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/szYuan/express-mysql-pool","tags":["javascript","express","mysql","connection","middleware","pool"],"install":[{"cmd":"npm install express-mysql-pool","lang":"bash","label":"npm"},{"cmd":"yarn add express-mysql-pool","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-mysql-pool","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; the module requires mysql to create pool and queries","package":"mysql","optional":false}],"imports":[{"note":"Package is CommonJS; use require or default import with ESM interop.","wrong":"const myConn = require('express-mysql-pool')","symbol":"default (function)","correct":"import myConn from 'express-mysql-pool'"},{"note":"In CommonJS, require returns the function directly, not an object with default property.","wrong":"const myConn = require('express-mysql-pool').default","symbol":"default (require)","correct":"const myConn = require('express-mysql-pool')"},{"note":"getConnection is callback-based, not Promise-based. No promise version available.","wrong":"req.getConnection().then(conn => ...)","symbol":"request.getConnection","correct":"req.getConnection(function(err, conn) { ... })"}],"quickstart":{"code":"var mysql = require('mysql');\nvar myConn = require('express-mysql-pool');\nvar express = require('express');\nvar app = express();\n\nvar dbOptions = {\n    host: 'localhost',\n    user: process.env.DB_USER || 'root',\n    password: process.env.DB_PASS || '',\n    database: 'test'\n};\n\napp.use(myConn(mysql, dbOptions));\n\napp.get('/api/foods', function(req, res, next) {\n    req.getConnection(function(err, conn) {\n        if(err) return next(err);\n        conn.query('SELECT * FROM food', function(err, results) {\n            if(err) return next(err);\n            res.json(results);\n        });\n    });\n});\n\napp.listen(3000);","lang":"javascript","description":"Sets up Express middleware to attach MySQL pool connection to each request, queries a table, returns JSON."},"warnings":[{"fix":"Wrap req.getConnection and conn.query in util.promisify or use mysql2/promise.","message":"Uses old callback style. No Promise or async/await support.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Ensure you use the 'mysql' package (not mysql2) unless compatibility is confirmed.","message":"Requires mysql module as first argument; passing wrong module (e.g., mysql2) may not work correctly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Switch to mysql2 for modern features and security updates.","message":"The 'mysql' package itself is in maintenance mode; consider migrating to mysql2.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.0.3':26 'altern':44 'around':33 'attach':13 'automat':12 'connect':10,15,43,48,50,57 'end':24 'express':2,5,46,55 'express-mysql-connect':45 'express-mysql-pool':1 'focus':38 'individu':49 'javascript':54 'latest':27 'middlewar':6,58 'modern':53 'modul':35 'mysql':3,9,34,47,56 'mysql2/promise':51 'pool':4,11,37,52,59 'provid':8 'recent':29 'releas':20 'request':18,41 'request-scop':40 'respons':23 'scope':42 'simpl':31 'updat':30 'version':25 'wrapper':32","created_at":"2026-06-05T16:56:23.410611+00:00","updated_at":"2026-06-05T16:56:23.410611+00:00","problems":[{"fix":"Ensure app.use(myConn(mysql, dbOptions)) is called before routes that use req.getConnection.","cause":"Middleware not applied correctly or not applied to the route path.","error":"TypeError: req.getConnection is not a function"},{"fix":"Use separate connections for parallel queries or chain them with callbacks.","cause":"Trying to use the same connection for multiple parallel queries without releasing.","error":"Error: Cannot enqueue Query after executing a query"},{"fix":"Restart MySQL server or reinitialize middleware.","cause":"MySQL server went down or pool was manually ended.","error":"Error: Pool is closed"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/szYuan/express-mysql-pool#readme","github":"https://github.com/szYuan/express-mysql-pool","docs":null,"changelog":null,"pypi":null,"npm":"express-mysql-pool","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}