I am using NodeJS and mysql library to access MySQL database.

When I establish single connection and repeatedly use it, it works fine:

global.mysql = mysql_module.createConnection({

host: config.mysql.host,

user: config.mysql.user,

password: config.mysql.password

When I use connection pool instead, I get ER_LOCK_WAIT_TIMEOUT errors in transactions.

global.mysql = mysql_module.createPool({

host: config.mysql.host,

user: config.mysql.user,

password: config.mysql.password,

database : config.mysql.database,

connectionLimit : 50

Strangely enough, the errors do occur on exactly the same data at exactly the same times.

I.e. I have transaction in which I insert in three tables in a row, each time using last inserted ID from previous INSERT statement. With some data this works fine, with some data, the third INSERT produces ER_LOCK_WAIT_TIMEOUT error. When I use single connection in NodeJS, this works fine, so this must be problem related to connection pool.

Any help would be appreciated.

No a big fan of asnwering my own questions, but problem is solved by explicitly creating connection from a pool and using it for every sql statement during transaction

pool.getConnection(function(err, connection) {

connection.query( 'START TRANSACTION', function(err, rows) {

// do all sql statements with connection and then

connection.query( 'COMMIT', function(err, rows) {

connection.release();

I am using NodeJS and mysql library to access MySQL database.When I establish single connection and repeatedly use it, it works fine:global. mysql = mysql _module.createConnection({host: config. mysql .ho... //连接数据库 var Sequelize = require("sequelize"); var seq = new Sequelize('sequelize_demo', 'root', '654321', { host: '127.0.0.1', port: '3306', dialect: " mysql ", dialectOptions: 然后在项目入口文件(如app.js)的最前面引入require('dotenv').config() 新建.env文件,并添加 mysql 配置。 MYSQL _HOST=localhost // 必填 MYSQL _USER=root MYSQL _PASSWORD=123456 MYSQL _PORT=3306 MYSQL _DATABASE= // 必填 数据库名 二、事务和锁 t Author: bugall Wechat: bugallF Email: 769088641@qq.com Github: https://github.com/bugall Mysql 5.6 InnoDB 这并不是sequelize的bug,在涉及到connection pool的时候都... 在Navicate里按F6,然后输入show engine innodb status; 关于此命令信息的解读请看:show engine innodb status解读 找到 LATEST DETECTED DEADLOCK,如下图,里面有 死锁 的语句。 经查找发现,我有两个事务,一个是更新设备状态... Mysql 5.6 Innodb 1.起因我们有个需要事物的业务场景,上线之初一直运行正常,可是在晚上高峰的时候一直会有逻辑错误的问题,刚开始绝的是逻辑有问题。在阿里RDS后台发现出现大量的锁,主 的某些数据行持有锁不释放,其它的sql一直等待,知道deadlock报错。因为主 其它业务模块也会用到。所以是一个比较紧急的情况2.错误的代码代码可以简写为:DBSequelize.transac 为了提高数据库的IO速度,会 使用 连接池 做处理,但是在高并发的情况下,一条连接完成任务后不释放掉, 会 导致 链接池满负载 ,后面的请求将无法处理,程序就会出现阻塞。 因此,当一条连接完成它的任务后,我们必须将它释放掉。(基本操作如下:) var mysql = require(' mysql '); var pool = mysql .createPool({ host:'127.0.0.1', 最近在做一个个人项目,数据库尝试 使用 了mongodb、sqlite和 mysql 。分享一下关于 mysql 连接池 用法。项目部署于appfog,项目中我 使用 连接池 链接数据库,本地测试一切正常。上线以后,经过几次请求两个数据接口总是报503。一直不明就里,今天经过一番排查终于顺利解决了。1. mysql 链接普通模式 mysql 的普通用法如下所示:var mysql = require(' mysql '),e...