Lock wait timeout exceeded; try restarting transaction mysql报错

Lock wait timeout exceeded; try restarting transaction mysql报错

  • 问题描述:
  • 问题复现
    • 第一步:开启sql命令页面
    • 第二步:输入start transaction;开启一个事务
    • 第三步:输入update语句不要提交
    • 第四步:书写测试类
    • 第五步:查看锁
    • 第五步:等待错误出现
  • 原因分析
  • 解决方案
    • 一、杀掉锁
    • 二、重启mysql
    • 三、设置锁定等待时间改大

问题描述:

提示:最近项目中频繁出现 Lock wait timeout exceeded; try restarting transaction这个错误,把我们弄得痛苦不堪啊,为了解决问题,上网上找好多资料。

问题复现

终于把问题复现了。具体操作步骤如下(我使用的mysql工具是 navicat):

第一步:开启sql命令页面

Lock wait timeout exceeded; try restarting transaction mysql报错_第1张图片

第二步:输入start transaction;开启一个事务

第三步:输入update语句不要提交

UPDATE TABLENAME set time=null where id=29163;(切记不要 提交(commit;))

第四步:书写测试类

运行程序

public class StTest implements Runnable{
   
    private  static ApplicationContext applicationContext=null;
    private static AtomicInteger a=new AtomicInteger(0);
    static {
   
         applicationContext=new ClassPathXmlApplicationContext("classpath:application.xml");
    }
    public static void main(String[] args) throws Exception {
   
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i <10 ; i++) {
   
            executorService.execute(new aaaa());
        }
        if(!executorService.isTerminated()){
   
            executorService.shutdown();
        }
    }
 
    @Override
    public void run() {
   
     

你可能感兴趣的:(Lock wait timeout exceeded; try restarting transaction mysql报错)