programing

Node.js를 Maria에 연결할 수 없습니다.DB

javamemo 2023. 8. 18. 20:39
반응형

Node.js를 Maria에 연결할 수 없습니다.DB

알겠습니다. 그래서 이 코드로 서버 mariaDB에 node.js를 연결하려고 했습니다.

const mariadb = require('mariadb');
const pool = mariadb.createPool({
     host: 'mydb.com', 
     user:'myUser', 
     password: 'myPassword',
     connectionLimit: 5
});
async function asyncFunction() {
  let conn;
  try {
    conn = await pool.getConnection();
    const rows = await conn.query("SELECT 1 as val");
    console.log(rows); //[ {val: 1}, meta: ... ]
    const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
    console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }

  } catch (err) {
    throw err;
  } finally {
    if (conn) return conn.end();
  }
}

불행하게도.작동하지 않습니다.이상한 것은 제가 어떠한 오류 메시지도 받지 못했다는 것입니다.제가 어떤 부분에서 잘못했는지, 어떻게 고쳐야 하는지 알고 싶습니다.

저기! 여기 내가 사용하는 것이 있습니다.

const pool = mysql.createPool({
    connectionLimit : 100,
    host            : 'localhost',
    user            : 'rashid',
    password        : config.get('turing-password'),
    database        : config.get('turing-db-name'),
    multipleStatements:true
})

module.exports.connect = pool.getConnection(function(err, connection) {
    if(err) 
        logger.info('we could not connect to the database');
    
    logger.info('We successfully connected to the database');
  })

localhost에서 실행 중인 호스트가 localhost로 사용되는지 확인하십시오.

언급URL : https://stackoverflow.com/questions/70349984/cant-connect-node-js-to-mariadb

반응형