zoukankan      html  css  js  c++  java
  • com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction

    问题描述:com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction  

    方案一、临时解决此问题 

    查找出此问题的thread ID ,然后进行KILL掉
    select * from information_schema.innodb_trx;

    -- kill 掉
    kill 240532;

    方案二、更改数据库超时时间


    1.查看当前锁超时时间

    show variables like 'innodb_lock_wait_timeout';

    2.查看全局锁超时时间

    SHOW GLOBAL VARIABLES LIKE 'innodb_lock_wait_timeout';

    3.更改当前锁超时时间为120秒

    SET innodb_lock_wait_timeout=120;

    4.更改全局锁超时时间为120秒

    SET GLOBAL innodb_lock_wait_timeout=120;

    (引起此类问题的发生,大部分都是库内的某一些存储过程事物提交超过了当前时间)

    方案三、检查innodb_rollback_on_timeout是否开启

    show VARIABLES like 'innodb_rollback_on_timeout';

    SET innodb_rollback_on_timeout=1; (1=OFF/0=ON)

    MySQL的官网对这个参数的解释,大概就是说在MySQL 5.6&5.7中默认值为OFF,当InnoDB默认情况下仅回滚事务超时的最后一条语句。如果innodb_rollback_on_timeout值为ON,则事务超时后将导致InnoDB中止并回滚整个事务。到这儿问题大概就清晰了,因为这个参数,所以这个事务只回滚了最后出现死锁的那条SQL,将这个值改成ON,再测试发现一切正常。

    --------------------------------------------------------------------------------------------------------------------

    具体解决思路:

    在navicat中执行程序日志中的报错

    UPDATE sp_jl SET jzt = 7 WHERE jpkid = '1314398431274868737'

    navicat报错:[Err] 1205 - Lock wait timeout exceeded; try restarting transaction

    select * from sp_jl limit 10 ;发现可以执行

    update另外一条数据试试

    UPDATE sp_jl SET jzt = 7 WHERE jpkid = '测试的主键';发现可以

    说明只有那一条数据被锁住了

    SELECT
    concat('kill',' ', trx_mysql_thread_id,';')
    FROM
    information_schema.innodb_trx

  • 相关阅读:
    WPF 分页控件Pager
    vue Map 渲染DOM
    IDEA 开发工具 Mybatis 快速开发插件 ==》MyBatisX
    令自己的本地ip可以被外网访问
    mybatis按datetime条件查询,参数为时间戳时
    springmvc传参---LocalDateTime、Date等时间类型转换
    java excel导出(表头合并,多行表头)
    JMeter学习工具简单介绍
    idea项目 run、debug变灰色的问题
    vue的ui库使用Element UI,纯html页面,不使用webpack那玩意
  • 原文地址:https://www.cnblogs.com/tongcc/p/13893437.html
Copyright © 2011-2022 走看看