node mysql连接池
发布于 8 年前 作者 DominicHjj 3786 次浏览 来自 问答

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

4 回复

创建两个连接不行吗?

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'
});

@carlisliu 就是创建两个实例吧

@DominicHjj 是的,

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

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

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).

回到顶部