Mysql Connections超时与回送服务器

时间:2019-07-29 09:38:48

标签: mysql node.js loopback

我正在尝试将回送服务器与mysql数据库连接。当我写节点时。然后按Enter键,回送服务器将在localhost:3000 / exployer中运行。但是当我尝试检索数据时,服务器会因该错误而自动丢失。

 Microsoft Windows [Version 10.0.17134.885]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Khundokar Nirjor\Desktop\Loopback>cd cart

C:\Users\Khundokar Nirjor\Desktop\Loopback\cart> node .
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
Connection fails: Error: Handshake inactivity timeout
It will be retried for the next request.
events.js:180
      throw er; // Unhandled 'error' event
      ^

Error: Handshake inactivity timeout
    at Handshake.<anonymous> (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Protocol.js:160:17)
    at Handshake.emit (events.js:203:13)
    at Handshake._onTimeout (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\sequences\Sequence.js:124:8)
    at Timer._onTimeout (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Timer.js:32:23)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
    --------------------
    at Protocol._enqueue (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at PoolConnection.connect (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\Connection.js:119:18)
    at Pool.getConnection (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\Pool.js:48:16)
    at MySQL.connect (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-connector-mysql\lib\mysql.js:90:17)
    at Object.initializeDataSource [as initialize] (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-connector-mysql\lib\mysql.js:44:28)
    at DataSource.setup (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-datasource-juggler\lib\datasource.js:493:19)
    at new DataSource (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
    at Registry.createDataSource (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback\lib\registry.js:364:12)
    at dataSourcesFromConfig (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback\lib\application.js:570:19)
    at Function.app.dataSource (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback\lib\application.js:269:14)
    at C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-boot\lib\executor.js:191:9
    at C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-boot\lib\executor.js:282:5
    at Array.forEach (<anonymous>)
    at forEachKeyedObject (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-boot\lib\executor.js:281:20)
    at setupDataSources (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-boot\lib\executor.js:181:3)
Emitted 'error' event at:
    at DataSource.postInit (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-datasource-juggler\lib\datasource.js:480:16)
    at C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\loopback-connector-mysql\lib\mysql.js:102:19
    at Handshake.onConnect (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\Pool.js:58:9)
    at Handshake.<anonymous> (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\Connection.js:525:10)
    at Handshake._callback (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\Connection.js:491:16)
    at Handshake.Sequence.end (C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
    at C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Protocol.js:404:18
    at Array.forEach (<anonymous>)
    at C:\Users\Khundokar Nirjor\Desktop\Loopback\cart\node_modules\mysql\lib\protocol\Protocol.js:403:13
    at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 10000
}

C:\Users\Khundokar Nirjor\Desktop\Loopback\cart>

这是我的datasource.json

{
  "shoppingdatabase": {
    "host": "localhost",
    "port": 8081,
    "url": "",
    "database": "shoppingdatabase",
    "password": "",
    "name": "shoppingdatabase",
    "user": "root",
    "connector": "mysql",
    "connectTimeout": 300000

  }
}

这是model.json的代码

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "vendor": {
    "dataSource": "shoppingdatabase",
    "public": true
  },
  "product": {
    "dataSource": "shoppingdatabase",
    "public": true
  },
  "user": {
    "dataSource": "shoppingdatabase",
    "public": true
  },
  "ACL": {
    "dataSource": "shoppingdatabase",
    "public": false
  }
}

1 个答案:

答案 0 :(得分:0)

尝试将端口更改为3306-因为这是默认的MySQL端口。

   {
      "shoppingdatabase": {
      "host": "localhost",
      "port": 3306,
      "url": "",
      "database": "shoppingdatabase",
      "password": "",
      "name": "shoppingdatabase",
      "user": "root",
      "connector": "mysql",
      "connectTimeout": 300000
    }
  }

和您的config.json应该像。

{
  "restApiRoot": "/api",
  "host": "0.0.0.0",
  "port": 3000,
  "remoting": {
    "context": false,
    "rest": {
    "handleErrors": false,
    "normalizeHttpPath": false,
    "xml": false
  },
   "json": {
   "strict": false,
   "limit": "100kb"
  },
   "urlencoded": {
   "extended": true,
   "limit": "100kb"
  },
 "cors": false
}

}