Answer the question
In order to leave comments, you need to log in
How can I keep multiple MySQL connections to different databases in nodeJS?
Good day friends! The question arose of how to simultaneously hold and access a specific connection to a particular database (on MySQL, of course). Without breaking connections.
Answer the question
In order to leave comments, you need to log in
Easily.
Also just to another variable.
mysql = require('mysql');
// первое
dbConn1 = mysql.createConnection({
host: DB_HOST,
user: DB_USER,
password: DB_PASSWORD,
database: "database1"
});
dbConn1.connect ( function() {
console.log('connecting to db1');
})
// и второе
dbConn2 = mysql.createConnection({
host: DB_HOST,
user: DB_USER,
password: DB_PASSWORD,
database: "database2"
});
dbConn2.connect( function() {
console.log('connecting to db2');
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question