Registry / database / loopback-connector-mysql-new-instance

loopback-connector-mysql-new-instance

JSON →
library5.4.2jsnpmunverified

The `loopback-connector-mysql` package is the official MySQL connector for the LoopBack framework (loopback-datasource-juggler), enabling MySQL database integration in LoopBack applications. The current version is 5.4.2, last updated in 2020, and it is in maintenance mode - not under active development. It supports MySQL 5.0+ and uses the `mysql` npm package under the hood. It provides automatic mapping between LoopBack model types and MySQL column types, connection pooling, and support for loopback-datasource-juggler operations. It is a legacy package; users are encouraged to migrate to LoopBack 4 and use `loopback-connector-mysql` compatible with LB4 or use `knex`-based connectors. This package should not be confused with newer versions for LoopBack 4.

npm install loopback-connector-mysql-new-instance
INSTALL
IMPORT
SIG · LOOPBACK-CONNECTOR
L
loopback-connector-mysql-new-instance
databasejavascriptv5.4.2
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.

MySQL connector
const MySQL = require('loopback-connector-mysql'); const ds = new MySQL('mysql', { host: 'localhost', database: 'test' });
import MySQL from 'loopback-connector-mysql'; // This is CJS-only; ESM not supported
This package is CommonJS only; don't use ES import syntax. Use require().
DataSource
const DataSource = require('loopback-datasource-juggler').DataSource; const ds = new DataSource('mysql', { host: 'localhost', database: 'test' });
new DataSource(require('loopback-connector-mysql'), ...); // Connector module is not a constructor; pass the connector name 'mysql'
Use the connector name 'mysql' as first argument, not the module itself.
Model creation
const User = ds.define('User', { name: String, email: String });
const User = ds.define('User', { name: 'string', email: 'string' }); // Type should be JavaScript constructor, not string
LoopBack accepts JavaScript type constructors (String, Number, Date) for property types.

Shows how to create a LoopBack MySQL data source, define a model, and create a record using callbacks.

const DataSource = require('loopback-datasource-juggler').DataSource; const ds = new DataSource('mysql', { host: process.env.MYSQL_HOST || 'localhost', port: process.env.MYSQL_PORT || 3306, database: process.env.MYSQL_DB || 'test', username: process.env.MYSQL_USER || 'root', password: process.env.MYSQL_PASSWORD || '', }); const User = ds.define('User', { name: String, email: { type: String, required: true }, age: Number, }); User.create({ name: 'John', email: 'john@example.com', age: 30 }, (err, user) => { if (err) console.error(err); else console.log('Created user:', user); });
Debug
Known issues
deprecatedThis package is for LoopBack 3 only. For LoopBack 4, use the official loopback-connector-mysql package.
fix
Update to LoopBack 4 and use loopback-connector-mysql from @loopback/loopback-connector-mysql or alternatively use knex-based connectors.
affects: >=5.0
breakingVersions before 2.0.0 used the name 'mysql' as connector name; some configurations may break when upgrading.
fix
Change datasource connector property to 'mysql' if it was using other connector names.
affects: <2.0
gotchaThe 'url' property overrides all other connection settings; mixing url with host/port/database can lead to connection errors.
fix
Use either url or individual connection properties (host, port, etc.), not both.
affects: >=1.0
gotchaThe connector uses the 'mysql' npm package which has its own configuration; some options (e.g. timezone) may behave differently than expected.
fix
Check the mysql package documentation for timezone handling; it stores dates as UTC by default.
affects: >=1.0
deprecatedSupport for Node.js versions <6 is deprecated; you should upgrade to Node 6+.
fix
Upgrade Node.js to version 6 or higher.
affects: >=5.0
Errors
Common errors & fixes
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
Missing or incorrect database credentials.
fix
Provide correct username and password in datasource configuration.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or not reachable at that host/port.
fix
Start MySQL service or check host/port settings.
TypeError: datasource.define is not a function
DataSource is not properly initialized; perhaps using wrong connector name or missing loopback-datasource-juggler.
fix
Ensure you require('loopback-datasource-juggler').DataSource and pass 'mysql' as the first argument.
Upgrade
Version history
5.4.2latest on npm
Audit
Dependencies
loopback-datasource-jugglerrequiredCore dependency for LoopBack ORM functionality; this connector plugs into it.
mysqlrequiredUnderlying MySQL driver for Node.js.
Agent activity
7 hits · last 30 days
node
6
Resources
loopback-connector-mysql-new-instance — npm install loopback-connector-mysql-new-instance · libregistry