N
N
Nikita Neskuchaev2016-10-13 19:34:43
Node.js
Nikita Neskuchaev, 2016-10-13 19:34:43

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

1 answer(s)
B
BestJS, 2016-10-16
@iamnikas

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 question

Ask a Question

731 491 924 answers to any question