Node.js를 원격 데이터베이스 Maria에 연결할 수 없습니다.DB
다음 튜토리얼에 따라 Node.js를 사용하여 MariaDB 데이터베이스에 접속하려고 합니다.
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'myhost.com',
user:'root',
password: 'password',
database: 'db_p',
connectionLimit: 2
});
async function asyncFunction() {
let conn;
try {
console.log('establishing connection')
conn = await pool.getConnection();
console.log('established')
const rows = await conn.query("SHOW TABLES");
console.log(rows);
} catch (err) {
console.log(err)
throw err;
} finally {
if (conn) return conn.end();
}
}
다만, 다음의 에러만 표시됩니다.
establishing connection
{ Error: retrieve connection from pool timeout
at Object.module.exports.createError (/Users/jan/Developer/microservice/node_modules/mariadb/lib/misc/errors.js:55:10)
at rejectTimeout (/Users/jan/Developer/microservice/node_modules/mariadb/lib/pool.js:267:16)
at Timeout.rejectAndResetTimeout [as _onTimeout] (/Users/jan/Developer/microservice/node_modules/mariadb/lib/pool.js:287:5)
at ontimeout (timers.js:486:15)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
fatal: false,
errno: 45028,
sqlState: 'HY000',
code: 'ER_GET_CONNECTION_TIMEOUT' }
(node:76515) UnhandledPromiseRejectionWarning: Error: retrieve connection from pool timeout
at Object.module.exports.createError (/Users/jan/Developer/microservice/node_modules/mariadb/lib/misc/errors.js:55:10)
at rejectTimeout (/Users/jan/Developer/microservice/node_modules/mariadb/lib/pool.js:267:16)
at Timeout.rejectAndResetTimeout [as _onTimeout] (/Users/jan/Developer/microservice/node_modules/mariadb/lib/pool.js:287:5)
at ontimeout (timers.js:486:15)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
(node:76515) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This errororiginated either by throwing inside of an async function without a catch block, or byrejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:76515) [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.
JS에서 지난 2년 동안 프로그래밍을 했지만, Node.js는 처음이라서 바로 사용할 수 있을 것이라고 생각했습니다.누구라도 있나요?
문제는 phpMyAdmin에서 접속할 수 있도록 홈 IP 주소를 추가하지 않았다는 것입니다.처음 사용하는 사용자에게는 동일한 이름과 비밀번호를 사용하여 여러 사용자를 만들 수 있으므로 여러 IP에서 실제로 액세스할 수 있습니다(예:localhost
,::1
또는127.0.0.1
이는 거의 동일하지만, 여전히 확실히 필요합니다.)
IP를 가리키는 동일한 자격 증명을 가진 사용자를 추가했더니 문제가 해결되었습니다.
같은 에러 메세지가 표시되는 다른 에러 메세지의 경우는, 특히 처음 몇회 접속이 동작하고 나서도 동작하지 않는 경우는, conn.end 로 접속을 종료하지 않으면 에러가 발생할 가능성이 있습니다.OP 문제가 아니라 다른 문제일 수 있습니다.
언급URL : https://stackoverflow.com/questions/53393660/cant-connect-node-js-to-remote-database-mariadb
'programing' 카테고리의 다른 글
webpack과 webpack의 Marge가 함수가 아닙니다. (0) | 2023.02.11 |
---|---|
고급 사용자 정의 필드 - 모든 페이지에 표시 (0) | 2023.02.11 |
특정 회선에 대한 eslint 규칙 해제 (0) | 2023.01.31 |
현재 시간(밀리초)을 PHP로 가져오는 방법 (0) | 2023.01.31 |
PHP에서 어레이와 데이터를 정렬하려면 어떻게 해야 합니까? (0) | 2023.01.31 |