Dandy Now!
  • [Node.js][Trouble Shooting] sqlMessage: "Access denied for user 'root'@'localhost' (using password: NO)"
    2022년 10월 08일 11시 46분 01초에 업로드 된 글입니다.
    작성자: DandyNow
    728x90
    반응형

     

    const pool = mysql.createPool({
      host: process.env.MYSQL_HOST,
      port: process.env.MYSQL_PORT,
      user: process.env.MYSQL_USERNAME,
      password: process.env.MYSQL_PASSWORD,
      database: process.env.MYSQL_DB,
      connectionLimit: process.env.MYSQL_LIMIT,
    });

    위는 mysql용 pool 작성 코드이다. 서버를 가동후 Postman에서 쿼리를 날리면 계속 아래와 같은 에러가 발생하였다. 문제의 원인은 황당하게도 오타였다. MYSQL_PASSWORD를 MYSQL_PASSWORLD로 작성했던 것.

     

    PS C:\Users\J\Documents\GitHub\Node-Practice> npm run prod
    
    > node-practice@1.0.0 prod
    > cross-env NODE_ENV=prod node 11_app_mysql.js
    
    서버가 포트 3000번으로 시작되었습니다.
    Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
        at Handshake.Sequence._packetToError (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
        at Handshake.ErrorPacket (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
        at Protocol._parsePacket (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Protocol.js:291:23)
        at Parser._parsePacket (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Parser.js:433:10)
        at Parser.write (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Parser.js:43:10)
        at Protocol.write (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Protocol.js:38:16)
        at Socket.<anonymous> (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\Connection.js:88:28)
        at Socket.<anonymous> (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\Connection.js:526:10)
        at Socket.emit (node:events:390:28)
        at addChunk (node:internal/streams/readable:315:12)
        --------------------
        at Protocol._enqueue (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Protocol.js:144:48)
        at Protocol.handshake (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\protocol\Protocol.js:51:23)
        at PoolConnection.connect (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\Connection.js:116:18)
        at Pool.getConnection (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\Pool.js:48:16)
        at Pool.query (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\mysql\lib\Pool.js:202:8)
        at C:\Users\J\Documents\GitHub\Node-Practice\mysql\index.js:25:10
        at new Promise (<anonymous>)
        at Object.query (C:\Users\J\Documents\GitHub\Node-Practice\mysql\index.js:24:10)
        at C:\Users\J\Documents\GitHub\Node-Practice\11_app_mysql.js:22:36
        at Layer.handle [as handle_request] (C:\Users\J\Documents\GitHub\Node-Practice\node_modules\express\lib\router\layer.js:95:5) {
      code: 'ER_ACCESS_DENIED_ERROR',
      errno: 1045,
      sqlMessage: "Access denied for user 'root'@'localhost' (using password: NO)",
      sqlState: '28000',
      fatal: true
    }
    node:internal/process/promises:246
              triggerUncaughtException(err, true /* fromPromise */);
              ^
    
    [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
      code: 'ERR_UNHANDLED_REJECTION'
    }

     

    728x90
    반응형
    댓글