本文介绍了帆无法连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个全新的Sails Projet上,我添加了:
On a brand new sails projet, I've added:
localMysql: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'homestead',
password: 'secret',
database: 'sails'
},
在config.connections.js上,并且:
on config.connections.js, and:
connection: 'localMysql',
migrate: 'alter'
在config.models.js上.在api/models/User.js上设置了用户模型:
on config.models.js. A user model is set on api/models/User.js:
// api/models/User.js
module.exports = {
attributes: {
appid: {
type: 'string'
},
uid: {
type: 'string'
},
hid: {
type: 'string'
},
params: {
type: 'string'
}
}
}
奔跑时,帆升起,我得到:
When running, sails lift, I obtain:
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)
同时,在我航行的同一文件夹中,我可以通过以下方式成功连接到mysql(sails数据库当前为空):
Meanwhile, on same folder I ran sails, I can successfully connect to mysql (sails database is currently empty) by:
mysql --user=homestead --password=secret --host=localhost --database=sails
sail和mysql都在无所事事的盒子中运行.
Both sails and mysql are running within a vagrant box.
有什么建议吗?
推荐答案
我将"localhost"更改为"127.0.0.1",并且对我有用.
I changed 'localhost' to '127.0.0.1' and it worked for me.
这篇关于帆无法连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!