반응형
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
반응형
'programing' 카테고리의 다른 글
Ajax를 사용하여 테이블 내용을 새로 고친 후 데이터 테이블을 다시 그리시겠습니까? (0) | 2023.08.18 |
---|---|
PHP에서 모호하고 잘못된 날짜 시간을 탐지하는 방법은 무엇입니까? (0) | 2023.08.18 |
두 열의 빠른 비교 방법 (0) | 2023.08.18 |
PowerShell에서 CSV로 내보낼 때 열 순서를 지정하려면 어떻게 해야 합니까? (0) | 2023.08.18 |
pip 설치를 사용하지 않고 tar.gz 파일에서 Python 패키지를 설치하는 방법 (0) | 2023.08.18 |