Registry / database / mysql-cli-exec

mysql-cli-exec

JSON →
library0.1.8jsnpmunverified

A MySQL command-line tool for Node.js that executes SQL statements and returns results as an object array. Current stable version 0.1.8, released in 2019. The package provides a simple promise-based API to run multiple SQL statements (e.g., USE, SELECT) in a single call, returning an array of row objects. It requires manual configuration of host/username/password and supports dynamic connections per query. This is a lightweight alternative to full ORM solutions like Sequelize, but lacks active maintenance.

npm install mysql-cli-exec
INSTALL
IMPORT
SIG · MYSQL-CLI-EXEC
M
mysql-cli-exec
databasejavascriptv0.1.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

init
const { init } = require('mysql-cli-exec'); init(config);
const myCli = require('mysql-cli-exec'); myCli.init(config);
Both patterns work; the package exports init and exec directly.
exec
const { exec } = require('mysql-cli-exec'); const result = await exec(sql);
const myCli = require('mysql-cli-exec'); const result = myCli.exec(sql);
exec returns a Promise, not a synchronous result.
do
const { do } = require('mysql-cli-exec'); const result = await do(sql);
const result = do(sql);
do is an alias for exec; both return Promises.

Shows how to initialize the library with connection config, execute SQL, and handle the returned array.

const config = { host: '127.0.0.1', username: 'root', password: 'playboy' }; const myCli = require('mysql-cli-exec'); myCli.init(config); const sql = `use sys; select * from sys_config;`; myCli.exec(sql).then(result => { console.log(result[0].variable); }).catch(err => console.error(err));
Debug
Known issues
deprecatedPackage is not actively maintained (last release 2019). Consider using mysql2 or @mysql/xdevapi.
fix
Migrate to mysql2: npm install mysql2 and use its promise API.
affects: >=0.0.0
gotchaThe returned array is flat: multiple SQL statements produce one large array, not separate arrays per statement.
fix
Parse results manually or use multiple exec calls.
affects: >=0.0.0
gotchaNo TypeScript definitions provided; use @types/mysql-cli-exec if available (none exist).
fix
Create custom type declarations or use require() with JSDoc.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: myCli.init is not a function
CommonJS require result is the default export, not a namespace. The package exports init directly.
fix
Use `const { init } = require('mysql-cli-exec');` instead of `const myCli = require('mysql-cli-exec'); myCli.init(...)`
Cannot read property 'length' of undefined
exec() returns a Promise, but it's used synchronously.
fix
Use async/await or .then(): `const result = await myCli.exec(sql);`
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid credentials or permissions.
fix
Ensure config.username, config.password, and config.host are correct.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies
mysqlrequiredThe underlying MySQL driver for Node.js
Agent activity
5 hits · last 30 days
node
4
Resources
mysql-cli-exec — npm install mysql-cli-exec · libregistry