Sails cannot connect to mySql
In the new projet sail, I added:
localMysql: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'homestead',
password: 'secret',
database: 'sails'
},
in your config.connections.js file and:
connection: 'localMysql',
migrate: 'alter'
in config.models.js. The custom model is installed at api / models / User.js:
// api/models/User.js
module.exports = {
attributes: {
appid: {
type: 'string'
},
uid: {
type: 'string'
},
hid: {
type: 'string'
},
params: {
type: 'string'
}
}
}
When working, raising the sails, I get:
error: A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
: Could not connect to MySQL:
Error: connect ECONNREFUSED
at afterwards (/home/vagrant/sails/track/node_modules/sails-mysql/lib/connections/spawn.js:75:13)
at /home/vagrant/sails/track/node_modules/sails-mysql/lib/connections/spawn.js:40:7
at Pool.<anonymous> (/home/vagrant/sails/track/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:47:16)
at Handshake.Sequence.end (/home/vagrant/sails/track/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24)
at Protocol.handleNetworkError (/home/vagrant/sails/track/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:282:14)
at PoolConnection.Connection._handleNetworkError (/home/vagrant/sails/track/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:303:18)
at Socket.emit (events.js:95:17)
at net.js:440:14
at process._tickDomainCallback (node.js:463:13)
Meanwhile, in the same folder I have managed the sails, I can successfully connect to mysql (the sails database is currently empty):
mysql --user=homestead --password=secret --host=localhost --database=sails
Both sail and mysql are running in a roving field.
Any suggestion?
source to share
There is nothing wrong with your sail configuration. I copied the code and tested it at the end. Make sure you have all the required permissions for the database you are trying to access. Just connecting to a database doesn't mean you have all the permissions you need. Try it sails lift
after executing below query while logged in as administrator in mysql
GRANT ALL PRIVILEGES ON sails.* TO 'homestead'@'%' WITH GRANT OPTION;
source to share