{"id":43249,"library":"mysql-async-simple","title":"mysql-async-simple","description":"A minimal async/await wrapper around the standard `mysql` package for Node.js (v1.0.3). It provides three simple functions: `makeDb`, `db.connect`, `db.query`, and `db.close`. Unlike alternatives like `mysql2` or `mysql2/promise`, this library keeps the familiar `mysql` API but returns promises. It has no additional dependencies beyond `mysql`, but does not support TypeScript types out-of-the-box. Low release cadence; last update was in 2020.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/hashgit/mysql-async-simple","tags":["javascript","mysql","async","nodejs"],"install":[{"cmd":"npm install mysql-async-simple","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-async-simple","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-async-simple","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: the library wraps the mysql client and requires it to be installed separately.","package":"mysql","optional":false}],"imports":[{"note":"This package is CommonJS-only. ESM import syntax (e.g. in TypeScript with esModuleInterop) may not work. Use require or set up a bundler accordingly.","wrong":"import { makeDb } from 'mysql-async-simple';","symbol":"makeDb","correct":"const { makeDb } = require('mysql-async-simple');"},{"note":"makeDb() is a factory function, not a constructor. Calling it with 'new' will throw a TypeError.","wrong":"const db = new makeDb();","symbol":"db","correct":"const db = makeDb();"},{"note":"Unlike the original mysql connection, the query method requires the connection object as the first argument. Forgetting it will pass the SQL string as the connection and cause a runtime error.","wrong":"const rows = await db.query(sql);","symbol":"query","correct":"const rows = await db.query(connection, sql);"}],"quickstart":{"code":"const { makeDb } = require('mysql-async-simple');\nconst mysql = require('mysql');\n\nconst connection = mysql.createConnection({\n  host: process.env.HOST ?? 'localhost',\n  user: process.env.USER ?? 'root',\n  password: process.env.PASSWORD ?? '',\n  database: process.env.DB ?? 'test'\n});\n\nconst db = makeDb();\n\nasync function run() {\n  try {\n    await db.connect(connection);\n    const users = await db.query(connection, 'SELECT * FROM users');\n    console.log(users);\n  } catch (err) {\n    console.error(err);\n  } finally {\n    await db.close(connection);\n  }\n}\n\nrun();","lang":"javascript","description":"Shows async/await usage with mysql-async-simple: create connection, wrap with makeDb(), connect, query, close."},"warnings":[{"fix":"Always pass the connection object as first argument: await db.query(connection, sql).","message":"TypeError: connection.query is not a function when calling db.query() with missing connection argument.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call const db = makeDb() before using db.connect().","message":"TypeError: db.connect is not a function if you forget to call makeDb() first.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install the peer dependency: npm install mysql mysql-async-simple","message":"Error: Cannot find module 'mysql' if mysql package is not installed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Switch to mysql2 (which has built-in promise support) or use mysql-async-simple with mysql2 if compatible, but prefer native promise API.","message":"The MySQL npm package (mysql) is no longer maintained. Consider using mysql2 for better performance and ongoing support.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use require() or transpile with Babel/TypeScript.","message":"Cannot use import syntax in pure Node.js without transpilation.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2020':68 'addit':46 'altern':28 'api':39 'around':9 'async':3,71 'async/await':7 'beyond':48 'box':60 'cadenc':63 'db.close':26 'db.connect':23 'db.query':24 'depend':47 'familiar':37 'function':21 'javascript':69 'keep':35 'last':64 'librari':34 'like':29 'low':61 'makedb':22 'minim':6 'mysql':2,12,38,49,70 'mysql-async-simpl':1 'mysql2':30 'mysql2/promise':32 'node.js':15 'nodej':72 'out-of-the-box':56 'packag':13 'promis':42 'provid':18 'releas':62 'return':41 'simpl':4,20 'standard':11 'support':53 'three':19 'type':55 'typescript':54 'unlik':27 'updat':65 'v1.0.3':16 'wrapper':8","created_at":"2026-06-05T16:58:53.902376+00:00","updated_at":"2026-06-05T16:58:53.902376+00:00","problems":[{"fix":"First call const db = makeDb(), then use db.query(connection, sql).","cause":"Attempting to call query directly on the connection object created by mysql, not on the wrapped db object.","error":"TypeError: db.query is not a function"},{"fix":"Start MySQL service or check host/port in connection options.","cause":"MySQL server not running or connection config incorrect.","error":"Error: connect ECONNREFUSED 127.0.0.1:3306"},{"fix":"Ensure const db = makeDb(); is executed successfully.","cause":"The db variable is undefined because makeDb() returned undefined (e.g., if you forgot to assign it).","error":"TypeError: Cannot read property 'query' of undefined"}],"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/hashgit/mysql-async-simple#readme","github":"https://github.com/hashgit/mysql-async-simple","docs":null,"changelog":null,"pypi":null,"npm":"mysql-async-simple","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}}