2017-02-07 76 views
0
error: A hook (`orm`) failed to load! 
error: Error (E_UNKNOWN) :: Encountered an unexpected error 
: Could not connect to MySQL: 
Error: connect ECONNREFUSED 127.0.0.1:3306 
    at afterwards (/root/sails/sailsUserApp/node_modules/sails-mysql/lib/connections/spawn.js:72:13) 
    at /root/sails/sailsUserApp/node_modules/sails-mysql/lib/connections/spawn.js:40:7 
    at Handshake.onConnect [as _callback] (/root/sails/sailsUserApp/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:54:9) 
    at Handshake.Sequence.end (/root/sails/sailsUserApp/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24) 
    at Protocol.handleNetworkError (/root/sails/sailsUserApp/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:364:14) 
    at PoolConnection.Connection._handleNetworkError (/root/sails/sailsUserApp/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:421:18) 
    at emitOne (events.js:96:13) 
    at Socket.emit (events.js:189:7) 
    at emitErrorNT (net.js:1280:8) 
    at _combinedTickCallback (internal/process/next_tick.js:74:11) 
    at process._tickDomainCallback (internal/process/next_tick.js:122:9) 

connection.js -獲取錯誤,當我連接mysql帆JS(節點 - V7.5.0)

Mysql: 
{ 
    adapter: 'sails-mysql', 
    host: 'localhost', 
    port: '3306', 
    user: 'root', //optional 
    password: '[email protected]', //optional 
    database: 'sails_users' //optional 
} 

models.js - connection: 'Mysql',

我不能找出問題。 端口:3306已在配置中提及。

+0

你在哪裏指定數據庫配置,您可以添加的那部分? –

+0

在connections.js文件 - MySQL的:{ 適配器: '帆-mysql的', 主持人: '本地主機', 端口: '3306', 用戶: '根',//可選 密碼:「SIPL @ 1234',//可選 數據庫:'sails_users'//可選 }, –

+0

您是否能夠使用命令行中的相同證書連接到MySQL 'mysql -u root -psipl @ 1234 sails_users'?請用你的'connections.js'文件的內容更新你的問題。 – Sangharsh

回答

1

MySQL連接參數將取決於MySQL配置。配置文件位置和默認連接訪問控制列表將取決於運行MySQL的操作系統以及傳遞給安裝的選項。

它可能期望Unix Socket連接而不是TCP連接。查看你的MySQL配置文件,看看哪些連接和用戶是允許的。如果它只允許套接字連接,那麼會有一個特定的unix套接字,它期望使用。

有了這些信息,您可以相應地設置配置參數。

要使用套接字連接的參數是:

Mysql: 
{ 
    adapter: 'sails-mysql', 
    socketPath: 'path-to-socket/mysql.sock', 
    user: 'mysql-user', 
    password: 'mysql-password', 
    database: 'mysql-database' 
}