首页 > 解决方案 > 如何将快递服务器与aws实例中的数据库连接起来

问题描述

我正在使用 express 和 typescript 制作服务器,但我无法将服务器连接到我在 aws 实例中拥有的数据库,这是服务器代码:

import { createPool } from 'mysql2';
  export async function conectar() {
      const conectando = await createPool({
          host:'myIPInstance',
          port: 3306,
          user:'myuser',
          password:'mypass',
          database:'example',
          connectionLimit: 10
      });
      return conectando;
  }

当我查看表格的内容时,我收到以下错误:

 (node:4704) [DEP0018] DeprecationWarning: Unhandled promise rejections 
  are deprecated. In the future, promise rejections that are not handled 
  will terminate the Node.js process with a non-zero exit code.
  [1] events.js:177
  [1]       throw er; // Unhandled 'error' event
  [1]       ^
  [1] 
  [1] Error: getaddrinfo ENOTFOUND https://3.13.108.243
  [1]     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
  [1] Emitted 'error' event at:
  [1] at /home/node_modules/mysql2/lib/pool.js:143:20
  [1] at /home/node_modules/mysql2/lib/pool.js:59: 18
  [1] at PoolConnection.<anonymous (/home/node_modules/mysql2/lib/connection.js:716:13)
  [1] at Object.onceWrapper (events.js:288:20)
  [1] at PoolConnection.emit (events.js:205:15)
  [1] at PoolConnection._notifyError (/home/node_modules/mysql2/lib/connection.js:212:12)
  [1] at PoolConnection._handleFatalError (/home/node_modules/mysql2/lib/connection.js:151:10)
  [1] at PoolConnection._handleNetworkError (/home/node_modules/mysql2/lib/connection.js:160:10)
  [1]     at Socket.emit (events.js:200:13)
  [1]     at emitErrorNT (internal/streams/destroy.js:91:8) {
  [1]   errno: 'ENOTFOUND',
  [1]   code: 'ENOTFOUND',
  [1]   syscall: 'getaddrinfo',
  [1]   hostname: 'MyIpInstance',
  [1]   fatal: true
  [1] }

我该如何解决这个错误,我需要什么?

标签: mysqlexpressserver

解决方案


推荐阅读