跳到主要内容
CNode

node mysql连接池

问答
DDominicHjj发布于 10 年前最后回复 10 年前
444210

描述: 现在项目有一个数据库,要新开一个项目但是这个项目的表要重新放在一个库里,但是还要依赖以前库的表,想问node有无这样的中间件,应该就类似 淘宝的druid连接池一样,求回答啊

查看回复

回复 (4)

MySQL offers a changeUser command that allows you to alter the current user and other aspects of the connection without shutting down the underlying socket:

connection.changeUser({user : 'john'}, function(err) {
  if (err) throw err;
});

The available options for this feature are:

user: The name of the new user (defaults to the previous one). password: The password of the new user (defaults to the previous one). charset: The new charset (defaults to the previous one). database: The new database (defaults to the previous one).

引用 DominicHjj@carlisliu 就是创建两个实例吧

@DominicHjj 是的,

var result1 = connection1.query('sql');
connection2.save('update table set col = ?', [result1.rows.length]);

类似这样,一个connection操作一个库

D
DominicHjj#210 年前

创建两个连接不行吗?

var connection1 = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  database : 'my_db1'
});

var connection2 = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  database : 'my_db2'
});

参与回复

登录后即可参与回复。登录