简体   繁体   English

更新数据库时出错:超过了锁定等待超时

[英]Error updating database:Lock wait timeout exceeded

I used MyBatis, I want to update data in the database, the insert query works but i have this error in the update. 我使用MyBatis,我想更新数据库中的数据,插入查询有效,但更新中出现此错误。

Error updating database.  Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

SqlMapConfig.xml SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost/test"/>
                <property name="username" value="root"/>
                <property name="password" value="***"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
      <mapper resource="config/UserMapper.xml"/>
    </mappers>
</configuration>

UserMapper.xml UserMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.UserDao">
    <update id="update" parameterType="User">
        update user set adress_u = #{adress_u} where id_u = #{id_u}
    </update>
</mapper>  

Test.java Test.java

String adress_u = (String) request.getAttribute("adress_u");
int id_u = (Integer) request.getAttribute("id_u");

SqlSession session = MyBatisSqlSessionFactory.getSession();
User u = new User();
u.setId_u(id_u);
u.setAdress_u(adress_u);

session.update("dao.UserDao.update", u);
session.commit();
session.close();

Thanks. 谢谢。

You should consider increasing the lock wait timeout value for InnoDB by setting the innodb_lock_wait_timeout, default is 50 sec 您应该考虑通过设置innodb_lock_wait_timeout来增加InnoDB的锁定等待超时值,默认值为50秒

mysql> show variables like 'innodb_lock_wait_timeout';

You can set it to higher value and restart mysql : 您可以将其设置为更高的值,然后重新启动mysql:

SET GLOBAL innodb_lock_wait_timeout = 120; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM