gpt4 book ai didi

mysql - Sails 无法连接到 mySql

转载 作者:可可西里 更新时间:2023-11-01 08:31:02 25 4
gpt4 key购买 nike

在一个全新的风 sails 项目上,我添加了:

localMysql: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'homestead',
password: 'secret',
database: 'sails'
},

在 config.connections.js 上,并且:

connection: 'localMysql',
migrate: 'alter'

在 config.models.js 上。在 api/models/User.js 中设置用户模型:

// api/models/User.js
module.exports = {

attributes: {
appid: {
type: 'string'
},
uid: {
type: 'string'
},
hid: {
type: 'string'
},
params: {
type: 'string'
}
}
}

运行时, sails 升起,我得到:

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)

同时,在我运行 sails 的同一文件夹中,我可以通过以下方式成功连接到 mysql(sails 数据库当前为空):

mysql --user=homestead --password=secret --host=localhost --database=sails

sails 和 mysql 都在一个 vagrant box 中运行。

有什么建议吗?

最佳答案

我将“localhost”更改为“127.0.0.1”,它对我有用。

关于mysql - Sails 无法连接到 mySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27406734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com