{"id":16796,"library":"database-js-mysql","title":"database-js-mysql","description":"database-js-mysql is a wrapper for the `mysql` package, primarily designed to integrate MySQL functionality into applications using the `database-js` abstraction layer. It provides a promise-based API for handling MySQL connections and executing queries, offering both standalone usage and integration with the `database-js` Connection class. As of its latest stable version, 1.1.3, released over seven years ago, the package relies on CommonJS modules and older JavaScript syntax. Its key differentiator was providing a consistent `database-js` interface for MySQL, including support for parameterized queries and streamlined connection management, which was useful for abstracting database interactions in its ecosystem.","status":"abandoned","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/mlaanderson/database-js-mysql","tags":["javascript","database-js","mysql"],"install":[{"cmd":"npm install database-js-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add database-js-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-js-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying MySQL driver for database operations.","package":"mysql","optional":false},{"reason":"Core abstraction layer for integrated use, optional for standalone mode.","package":"database-js","optional":true}],"imports":[{"note":"This package exclusively uses CommonJS modules (`require`). Native ES Modules (`import`) are not supported due to the project's age.","wrong":"import mysql from 'database-js-mysql';","symbol":"mysql","correct":"var mysql = require('database-js-mysql');"},{"note":"The `Connection` class is provided by the `database-js` package itself, not `database-js-mysql`. Ensure `database-js` is installed.","wrong":"import { Connection as Database } from 'database-js';","symbol":"Connection","correct":"var Database = require('database-js').Connection;"},{"note":"In standalone mode, the `open` static method on the `mysql` object (from `database-js-mysql`) is used to establish a connection.","symbol":"mysql.open","correct":"let connection = mysql.open({...});"}],"quickstart":{"code":"const mysql = require('database-js-mysql');\n\n(async () => {\n    let connection, rows;\n    try {\n        connection = mysql.open({\n            Hostname: process.env.DB_HOST ?? 'localhost',\n            Port: parseInt(process.env.DB_PORT ?? '3306', 10),\n            Username: process.env.DB_USERNAME ?? 'my_secret_username',\n            Password: process.env.DB_PASSWORD ?? 'my_secret_password',\n            Database: process.env.DB_DATABASE ?? 'my_top_secret_database'\n        });\n\n        // Ensure the connection is established before querying\n        rows = await connection.query(\"SELECT * FROM tablea WHERE user_name = 'not_so_secret_user'\");\n        console.log('Query result:', rows);\n    } catch (error) {\n        console.error('Database operation failed:', error);\n    } finally {\n        if (connection) {\n            await connection.close();\n            console.log('Connection closed.');\n        }\n    }\n})();","lang":"javascript","description":"This quickstart demonstrates how to establish a standalone MySQL connection using `database-js-mysql` and execute a simple query. It uses environment variables for sensitive credentials and handles connection opening, querying, and closing with async/await."},"warnings":[{"fix":"Consider migrating to actively maintained database drivers like `mysql2` or newer ORMs/query builders.","message":"The project appears to be abandoned, with no updates or commits in over seven years. This means it is unlikely to support modern Node.js versions, fix security vulnerabilities, or adopt new JavaScript features (e.g., native ESM).","severity":"breaking","affected_versions":">=1.1.3"},{"fix":"Use `require()` syntax for all imports from this package and ensure your project configuration is set up for CommonJS.","message":"This package is CommonJS-only and does not support native ES Modules (`import`/`export`). Attempting to `import` from it will result in errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Audit the `mysql` dependency for known CVEs. For new projects, prefer `mysql2` which is actively maintained and supports promises and modern features.","message":"The underlying `mysql` package (version ~2.10.x at the time of this wrapper's last update) may have known vulnerabilities or compatibility issues with modern MySQL server versions or Node.js runtimes. These issues will not be patched by `database-js-mysql`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that the paths provided for `ssl[ca]`, `ssl[key]`, and `ssl[cert]` are absolute, correct, and that the Node.js process has read permissions for these files. Test SSL connectivity thoroughly.","message":"SSL configuration requires file paths (e.g., `ssl[ca]`) to be correctly specified and readable by the Node.js process. Incorrect paths or permissions will lead to connection failures that can be difficult to debug.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const mysql = require('database-js-mysql');` and ensure your project is configured for CommonJS, or use a tool like Webpack/Rollup to transpile.","cause":"Attempting to import `database-js-mysql` using `import` statement in an ES Module context.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module"},{"fix":"Verify that the MySQL server is running, check the `Hostname`, `Port`, `Username`, and `Password` in your connection options, and ensure no firewalls are preventing access.","cause":"The MySQL server is not running, is configured to listen on a different port/host, or firewall rules are blocking the connection.","error":"Error: connect ECONNREFUSED"},{"fix":"Double-check your `Username` and `Password` in the connection object. Ensure the MySQL user has privileges to connect from the specified host and access the target database.","cause":"Incorrect username or password provided in the connection options, or the user lacks necessary permissions for the database.","error":"ER_ACCESS_DENIED_ERROR: Access denied for user '...'@'localhost' (using password: YES/NO)"},{"fix":"Ensure `let connection = await mysql.open({...});` is used to properly resolve the promise and get the connection object before calling methods on it.","cause":"This error often occurs if `mysql.open()` was not `await`ed or if the `connection` object somehow became `undefined` or not the expected promise-wrapped connection.","error":"TypeError: connection.query is not a function"}],"ecosystem":"npm","meta_description":null}