Can't connect Node.js to remote database MariaDB
I try to connect to my MariaDB database using Node.js based on this tutorial:
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();
}
}
but all I get is this error:
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.
I programmed in JS for last two years, but I'm new to Node.js and I thought it should work out of the box. Anyone?
node.js mariadb
|
show 1 more comment
I try to connect to my MariaDB database using Node.js based on this tutorial:
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();
}
}
but all I get is this error:
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.
I programmed in JS for last two years, but I'm new to Node.js and I thought it should work out of the box. Anyone?
node.js mariadb
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code pointslocalhost
so I found hostname in phpMyAdmin but still the same error
– jean d'arme
Nov 20 '18 at 13:24
I tried usingmysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server
– jean d'arme
Nov 20 '18 at 13:27
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
2
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47
|
show 1 more comment
I try to connect to my MariaDB database using Node.js based on this tutorial:
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();
}
}
but all I get is this error:
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.
I programmed in JS for last two years, but I'm new to Node.js and I thought it should work out of the box. Anyone?
node.js mariadb
I try to connect to my MariaDB database using Node.js based on this tutorial:
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();
}
}
but all I get is this error:
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.
I programmed in JS for last two years, but I'm new to Node.js and I thought it should work out of the box. Anyone?
node.js mariadb
node.js mariadb
asked Nov 20 '18 at 13:05
jean d'armejean d'arme
1,11221529
1,11221529
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code pointslocalhost
so I found hostname in phpMyAdmin but still the same error
– jean d'arme
Nov 20 '18 at 13:24
I tried usingmysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server
– jean d'arme
Nov 20 '18 at 13:27
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
2
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47
|
show 1 more comment
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code pointslocalhost
so I found hostname in phpMyAdmin but still the same error
– jean d'arme
Nov 20 '18 at 13:24
I tried usingmysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server
– jean d'arme
Nov 20 '18 at 13:27
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
2
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code points
localhost
so I found hostname in phpMyAdmin but still the same error– jean d'arme
Nov 20 '18 at 13:24
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code points
localhost
so I found hostname in phpMyAdmin but still the same error– jean d'arme
Nov 20 '18 at 13:24
I tried using
mysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server– jean d'arme
Nov 20 '18 at 13:27
I tried using
mysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server– jean d'arme
Nov 20 '18 at 13:27
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
2
2
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
The problem was that in phpMyAdmin I didn't added my home ip address so I can connect. For those who are just starting with it - you can create multiple users with the same name and password so you can actually have access from multiple IP's (like localhost
, ::1
or 127.0.0.1
which is quite the same, but still required just for sure).
I have added additional user with same credentials pointing to my IP and it solved the problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393660%2fcant-connect-node-js-to-remote-database-mariadb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem was that in phpMyAdmin I didn't added my home ip address so I can connect. For those who are just starting with it - you can create multiple users with the same name and password so you can actually have access from multiple IP's (like localhost
, ::1
or 127.0.0.1
which is quite the same, but still required just for sure).
I have added additional user with same credentials pointing to my IP and it solved the problem.
add a comment |
The problem was that in phpMyAdmin I didn't added my home ip address so I can connect. For those who are just starting with it - you can create multiple users with the same name and password so you can actually have access from multiple IP's (like localhost
, ::1
or 127.0.0.1
which is quite the same, but still required just for sure).
I have added additional user with same credentials pointing to my IP and it solved the problem.
add a comment |
The problem was that in phpMyAdmin I didn't added my home ip address so I can connect. For those who are just starting with it - you can create multiple users with the same name and password so you can actually have access from multiple IP's (like localhost
, ::1
or 127.0.0.1
which is quite the same, but still required just for sure).
I have added additional user with same credentials pointing to my IP and it solved the problem.
The problem was that in phpMyAdmin I didn't added my home ip address so I can connect. For those who are just starting with it - you can create multiple users with the same name and password so you can actually have access from multiple IP's (like localhost
, ::1
or 127.0.0.1
which is quite the same, but still required just for sure).
I have added additional user with same credentials pointing to my IP and it solved the problem.
answered Nov 21 '18 at 18:16
jean d'armejean d'arme
1,11221529
1,11221529
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393660%2fcant-connect-node-js-to-remote-database-mariadb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So the connection to the database timed out. Can you access the database through other means (like a command line client) from the machine that is also running your Node code?
– robertklep
Nov 20 '18 at 13:21
Not really. I have access to phpMyAdmin and the reason I use Node is because our developer is gone and I need to create microservice that connects to database so we're not left in the dark. PHP code points
localhost
so I found hostname in phpMyAdmin but still the same error– jean d'arme
Nov 20 '18 at 13:24
I tried using
mysql
package and I got `Error: ER_HOST_NOT_PRIVILEGED: Host 'my ip here' is not allowed to connect to this MariaDB server– jean d'arme
Nov 20 '18 at 13:27
That's another problem, but one that is possibly easier to solve (grant permission to the client's IP-address).
– robertklep
Nov 20 '18 at 13:28
2
@jeand'arme - Yes, that's the likely answer. Self-Answer this Question, then Accept your Answer. (Let's get this Question Closed without deleting it.)
– Rick James
Nov 20 '18 at 16:47