How to debug Lock wait timeout exceeded on MySQL?

前端 未结 11 1044
我寻月下人不归
我寻月下人不归 2020-11-22 11:46

In my production error logs I occasionally see:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction

11条回答
  •  被撕碎了的回忆
    2020-11-22 12:10

    The big problem with this exception is that its usually not reproducible in a test environment and we are not around to run innodb engine status when it happens on prod. So in one of the projects I put the below code into a catch block for this exception. That helped me catch the engine status when the exception happened. That helped a lot.

    Statement st = con.createStatement();
    ResultSet rs =  st.executeQuery("SHOW ENGINE INNODB STATUS");
    while(rs.next()){
        log.info(rs.getString(1));
        log.info(rs.getString(2));
        log.info(rs.getString(3));
    }
    

提交回复
热议问题