在风帆升降机上,MySql无法连接到Sailsjs

时间:2017-11-02 07:26:41

标签: mysql sails.js

我刚刚开始在sailsjs编码,我正在尝试将其连接到Mysql数据库。我已经安装了“sails-mysql”。我还使用mysql命令创建了数据库。这些是我的'config'文件的内容。一世 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'
};

我在'风帆升降机'上得到了这个错误。

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)

导致此错误的原因是什么?如何解决? 在此先感谢:)

1 个答案:

答案 0 :(得分:0)

你应该将mysql端口更改为330627017为mongodb,添加mysql连接的用户名和密码,并确保通过在mysql shell上测试它来传递正确的凭据: -

mysql -u USERNAME -pPASSWORD -d DBNAME   

这是一个mysql-config的示例,它的外观如何

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'
  }
};