mysql某张表一直卡死,排查原因和问题解决

本文介绍了如何诊断并解决MySQL中表卡死的问题。通过查询`information_schema.processlist`来查找占用资源的SQL命令,特别是那些长时间运行的进程。通过`information_schema.innodb_trx`找出具体的事务ID,并使用`kill`命令终止导致卡死的进程。这种方法有助于恢复正常的数据操作和维护数据库稳定性。
摘要由CSDN通过智能技术生成

mysql某张表一直卡死

查看哪些运行的命令造成,如sql语句等

select id, db, user, host, command, time, state, info
from information_schema.processlist
where command != 'Sleep'
order by time desc ;

查看那个端口运行了命令和命令执行的开始时间,根据端口开始时间长的将它杀死
查看端口运行的命令和执行的时间,将端口运行时间长的杀死
select * from information_schema.innodb_trx;
然后删除某个trx_mysql_thread_id就可以了
trx_mysql_thread_id
kill 1111;

问题解决,能正常打开此表和相关sql操作

show processlist; 也可以查看卡死的sql,sql语句在info里面,没有则无

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot可以通过使用MySQL的binlog来实现实时监听某张表的变化。下面是一个基本的示例代码: 1. 在`application.properties`文件中添加以下配置: ``` spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=123456 spring.jpa.hibernate.ddl-auto=none spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect spring.jpa.show-sql=true spring.jpa.open-in-view=false spring.jpa.properties.hibernate.default_schema=mydatabase spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.properties.hibernate.event.merge.entity_copy_observer=allow ``` 这里的`mydatabase`是你的数据库名称,`root`和`123456`是你的数据库用户名和密码。 2. 创建一个`DatabaseEventListener`类来监听数据库变化: ```java import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalEventListener; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Component public class DatabaseEventListener { @PersistenceContext private EntityManager entityManager; @EventListener @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void handleDatabaseEvent(DatabaseEvent event) { // 处理数据库变化事件 System.out.println("变化事件:" + event); } } ``` 这里的`DatabaseEvent`是自定义的事件类,你可以根据自己的需求定义自己的事件类。 3. 创建一个`DatabaseEvent`类来数据库变化事件: ```java public class DatabaseEvent { private String tableName; public DatabaseEvent(String tableName) { this.tableName = tableName; } public String getTableName() { return tableName; } public void setTableName(String tableName) { this.tableName = tableName; } @Override public String toString() { return "DatabaseEvent{" + "tableName='" + tableName + '\'' + '}'; } } ``` 4. 在需要监听的方法中,手动触发事件: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service public class ExampleService { @Autowired private ApplicationEventPublisher eventPublisher; @Transactional public void doSomethingAndTriggerEvent() { // 执行一些操作 // ... // 触发事件 eventPublisher.publishEvent(new DatabaseEvent("my_table")); } } ``` 这里的`my_table`是你需要监听的名。 以上就是一个基本的示例,你可以根据自己的需求进行修改和扩展。注意,需要确保MySQL的binlog功能已经开启。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值