Reputation: 23
I have just started coding in sailsjs, and i am trying to connect it to a Mysql database. I have installed "sails-mysql". I have also created the database using the mysql commands. These are the contents of my 'config' files. I connections.js
mysql: {
adapter: 'sails-mysql',
host: '127.0.0.1',
port: 27017,
user: '', //optional
password: '', //optional
database: 'new_db',
schema: true //optional
}
models.js
module.exports.models = {
connection: 'mysql',
migrate: 'alter'
};
I get this error on 'sails lift'.
error: A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
: Could not connect to MySQL:
Error: Handshake inactivity timeout
at afterwards
(/home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/lib/connections/spawn.js:72:13)
at /home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/lib/connections/spawn.js:40:7
at Handshake.onConnect
(/home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/node_modules/mysql/lib/Pool.js:54:9)
at Handshake.Sequence.end
(/home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at /home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/node_modules/mysql/lib/protocol/Protocol.js:399:18
at Array.forEach (native)
at /home/kshd97/Desktop/projects2/sails/actvity/node_modules/sails-
mysql/node_modules/mysql/lib/protocol/Protocol.js:398:13
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
What could be the cause of this error and how do i resolve it? Thanks in advance :)
Upvotes: 0
Views: 379
Reputation: 2964
you should change mysql port to 3306
as 27017
it's for mongodb, add username and password of mysql connection and make sure you are passing the correct credentials by test it on mysql shell :-
mysql -u USERNAME -pPASSWORD -d DBNAME
here is an example of mysql-config how it looks like
module.exports.connections = {
mysql: {
module : 'sails-mysql',
host : 'localhost',
port : 3306,
user : 'username',
password : 'password',
database : 'MySQL Database Name'
// OR (explicit sets take precedence)
module : 'sails-mysql',
url : 'mysql2://USER:PASSWORD@HOST:PORT/DATABASENAME'
// Optional
charset : 'utf8',
collation : 'utf8_swedish_ci'
}
};
Upvotes: 0