{"id":42421,"library":"async-mysql","title":"async-mysql","description":"async-mysql is a lightweight wrapper around the popular mysql npm package that enables async/await syntax for MySQL database operations. Its current stable version is 1.0.1, and it has not seen updates since 2017. The library provides a simple promise-based API, allowing developers to use ES7 async functions instead of callbacks. It is designed for Node.js environments and simplifies connection management and query execution. However, it does not support connection pooling or prepared statements directly, relying on the underlying mysql package for core functionality. The library is considered stable but feature-limited, and alternatives like mysql2 or knex offer more modern features.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/gajus/async-mysql.js","tags":["javascript","mysql","async","promise"],"install":[{"cmd":"npm install async-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add async-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add async-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"async-mysql is a wrapper around the mysql package; it relies on it for all database communication.","package":"mysql","optional":false}],"imports":[{"note":"The library does not export ES modules; CommonJS require is the correct usage.","wrong":"const async_mysql = require('async-mysql')","symbol":"default","correct":"import async_mysql from 'async-mysql'"},{"note":"connect is a named function on the default export, not a direct function call.","wrong":"const connection = await async_mysql({ host: 'localhost' });","symbol":"connect","correct":"const connection = await async_mysql.connect({ host: 'localhost' });"},{"note":"The returned object from connect has a query method that returns a promise; do not pass a callback.","wrong":"const rows = await connection.query('SELECT 1', callback);","symbol":"query","correct":"const rows = await connection.query('SELECT 1');"}],"quickstart":{"code":"const async_mysql = require('async-mysql');\n\nasync function main() {\n  const connection = await async_mysql.connect({\n    host: 'localhost',\n    user: 'root',\n    password: '',\n    database: 'test'\n  });\n\n  const rows = await connection.query('SELECT 1 AS result');\n  console.log(rows); // [ { result: 1 } ]\n\n  await connection.query('INSERT INTO users (name) VALUES (?)', ['John']);\n\n  const users = await connection.query('SELECT * FROM users');\n  console.log(users);\n}\n\nmain().catch(err => console.error(err));","lang":"javascript","description":"This example shows how to connect to a MySQL database, execute a SELECT query, insert a row with parameterized queries, and fetch all users."},"warnings":[{"fix":"Migrate to mysql2 with promise API or use knex for query building.","message":"No updates since 2017; consider using mysql2 or knex for active support.","severity":"deprecated","affected_versions":"all"},{"fix":"Implement your own pool using mysql's createPool or use a different library.","message":"The library does not support connection pooling; each connect call creates a new connection.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap queries in try/catch blocks to handle SQL errors appropriately.","message":"Error handling: query errors are thrown as Error objects with MySQL error message, not as custom exceptions.","severity":"gotcha","affected_versions":"all"},{"fix":"Always provide an array of values for parameterized queries to prevent SQL injection.","message":"Parameterized queries use MySQL's ? placeholder; array of values must match placeholder count.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.0.1':30 '2017':38 'allow':48 'altern':101 'api':47 'around':11 'async':2,5,53,112 'async-mysql':1,4 'async/await':19 'base':46 'callback':57 'connect':66,76 'consid':94 'core':89 'current':26 'databas':23 'design':60 'develop':49 'direct':81 'enabl':18 'environ':63 'es7':52 'execut':70 'featur':98,109 'feature-limit':97 'function':54,90 'howev':71 'instead':55 'javascript':110 'knex':105 'librari':40,92 'lightweight':9 'like':102 'limit':99 'manag':67 'modern':108 'mysql':3,6,14,22,86,111 'mysql2':103 'node.js':62 'npm':15 'offer':106 'oper':24 'packag':16,87 'pool':77 'popular':13 'prepar':79 'promis':45,113 'promise-bas':44 'provid':41 'queri':69 'reli':82 'seen':35 'simpl':43 'simplifi':65 'sinc':37 'stabl':27,95 'statement':80 'support':75 'syntax':20 'under':85 'updat':36 'use':51 'version':28 'wrapper':10","created_at":"2026-06-05T16:54:53.845115+00:00","updated_at":"2026-06-05T16:54:53.845115+00:00","problems":[{"fix":"Use const async_mysql = require('async-mysql'); (CommonJS) or if using ES modules, use a default import workaround.","cause":"The imported async_mysql object is not a module with a connect function due to incorrect import/require.","error":"TypeError: async_mysql.connect is not a function"},{"fix":"Provide correct host, user, password, and database in the connect configuration object.","cause":"Connection configuration missing user/password or wrong credentials.","error":"Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)"},{"fix":"Use Node.js 7.6+ or transpile with Babel and include the regenerator-runtime polyfill.","cause":"The runtime environment does not support async/await natively (older Node.js versions).","error":"ReferenceError: regeneratorRuntime is not defined"}],"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/gajus/async-mysql.js","github":"https://github.com/gajus/async-mysql.js","docs":null,"changelog":null,"pypi":null,"npm":"async-mysql","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}}