Registry / database / mysql-native

mysql-native

JSON →
library0.4.7jsnpmunverified

A pure-JavaScript MySQL client for Node.js (v0.4.7) that implements the MySQL wire protocol directly, requiring no native C++ addons or external MySQL runtime. It supports TCP and UNIX socket connections, automatic prepared statement caching, pipelined queries, and transparent handling of row and binary row packets. Released under a rolling cadence, this package is a legacy choice superseded by more modern MySQL drivers like mysql2 or mysql (felixge). It is best suited for older Node.js environments (>=0.6.0) or educational exploration of protocol internals.

npm install mysql-native
INSTALL
IMPORT
SIG · MYSQL-NATIVE
M
mysql-native
databasejavascriptv0.4.7
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.

createClient
import { createClient } from 'mysql-native'
const mysql = require('mysql-native'); const client = mysql.createClient();
Default export is an object with named functions; there is no default import.
createTCPClient
import { createTCPClient } from 'mysql-native'
const client = require('mysql-native').createTCPClient();
Both named import and property access work; no ESM/CJS differences pre-date ESM.

Connects to MySQL, authenticates, runs a simple query with event listeners, and closes the connection.

import { createTCPClient } from 'mysql-native'; const client = createTCPClient('localhost', 3306); client.auto_prepare = true; client.on('error', (err) => console.error(err)); client.auth('testdb', 'testuser', 'testpass'); client.query('SELECT 1+1 AS result') .on('field', (field) => console.log('Field:', field)) .on('row', (row) => console.log('Row:', row)) .on('end', () => client.close());
Debug
Known issues
deprecatedPackage has not been updated since 2012; consider using mysql2 or mysql.
fix
Migrate to a maintained driver like mysql2.
affects: >=0.0.0
gotchaauto_prepare must be set to true for execute() to work without manual prepare.
fix
Set client.auto_prepare = true before calling execute().
affects: >=0.0.0
gotchaEvent names on query/execute commands are lowercase (e.g., 'row', 'field', 'end') but Node.js style would expect 'row' etc. Already lowercase, but no 'data' event.
fix
Use 'row' for rows, 'field' for field metadata, 'end' for result completion.
affects: >=0.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED ::1:3306
Default host is IPv6 localhost; older Node versions or configurations may not resolve.
fix
Explicitly pass '127.0.0.1' instead of 'localhost' when calling createTCPClient.
TypeError: client.auth is not a function
Incorrect import — auth is a method on the client instance, not a standalone function.
fix
Ensure you create a client first: const client = createTCPClient(); then client.auth(...).
Upgrade
Version history
0.4.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
mysql-native — npm install mysql-native · libregistry