Registry / database / sails-mysql2

sails-mysql2

JSON →
library0.9.32jsnpmunverified

MySQL and MariaDB adapter for Sails.js, version 0.9.32. This is a fork of the official sails-mysql adapter that uses the mysql2 library instead of mysql. It supports both MySQL and MariaDB databases. The adaptation provides connection pooling, SSL, and authentication switch support. It is designed to work with Waterline ORM in Sails v1.0+. The adapter is maintained with irregular release cadence.

npm install sails-mysql2
INSTALL
IMPORT
SIG · SAILS-MYSQL2
S
sails-mysql2
databasejavascriptv0.9.32
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.

sails-mysql2
npm install sails-mysql2
npm install sails-mysql
This is a replacement for sails-mysql adapter; install explicitly by package name.
adapter configuration
adapter: 'sails-mysql2' in connections config
adapter: 'sails-mysql'
Use 'sails-mysql2' as the adapter name in Sails config.
default config
module.exports.models = { connection: 'mysql' }
module.exports.models = { adapter: 'sails-mysql2' }
In models config, set the connection name, not the adapter directly.

Configure Sails.js to use MySQL/MariaDB via sails-mysql2 adapter with environment variables for credentials.

// In your Sails app's config/connections.js module.exports.connections = { mysql: { adapter : 'sails-mysql2', host : process.env.MYSQL_HOST || 'localhost', port : process.env.MYSQL_PORT || 3306, user : process.env.MYSQL_USER || 'root', password : process.env.MYSQL_PASSWORD || '', database : process.env.MYSQL_DATABASE || 'sails_mysql', charset : 'utf8', collation : 'utf8_swedish_ci' } }; // In config/models.js module.exports.models = { connection: 'mysql' };
Debug
Known issues
gotchaAdapter name must be 'sails-mysql2' exactly, not 'sails-mysql' in connections config.
fix
Use 'sails-mysql2' as the adapter value.
affects: >=0.0.0
gotchaThe package uses mysql2 library which may have different default charset/collation than mysql.
fix
Explicitly set charset and collation in config if needed.
affects: >=0.0.0
breakingIn Sails v1.0+, the models config expects 'connection' key, not 'adapter'.
fix
Use module.exports.models = { connection: 'mysql' } instead of { adapter: '...' }.
affects: >=1.0.0
deprecatedThe 'url' configuration option may be deprecated in favor of explicit connection parameters.
fix
Use individual host/user/password/database fields instead of url.
affects: >=0.9.0
Errors
Common errors & fixes
Error: Adapter 'sails-mysql' not found
Using wrong adapter name in config
fix
Change adapter to 'sails-mysql2' in connections config.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or wrong host/port
fix
Ensure MySQL/MariaDB is running and host/port are correct.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user
Invalid credentials
fix
Verify username and password in connection config.
Error: Handshake inactivity timeout
Connection dropped due to network issue or firewall
fix
Increase connection timeout or check network connectivity.
Upgrade
Version history
0.9.32latest on npm
Audit
Dependencies
sailsrequiredPeer dependency; only works within Sails.js framework
waterlinerequiredRequires Waterline ORM to function
mysql2requiredDirect dependency for MySQL/MariaDB connectivity
Agent activity
56 hits · last 30 days
node
54
Meta
2
Resources
sails-mysql2 — npm install sails-mysql2 · libregistry