当前位置: 代码网 > it编程>数据库>Mysql > mysql数据库卡顿问题排查过程

mysql数据库卡顿问题排查过程

2025年02月28日 Mysql 我要评论
一、查看后台sql的运行情况这种能排查后台有进程一直占用资源,导致死锁1、查看正在执行的事务select * from information_schema.innodb_trx2、查看进程show

一、查看后台sql的运行情况

这种能排查后台有进程一直占用资源,导致死锁

1、查看正在执行的事务

select * from information_schema.innodb_trx

2、查看进程

show processlist

3、杀死进程

kill 123

二、查看库和表信息

这种能排查是资源不够用的情况

1、据库大小和索引大小

-- 据库大小和索引大小
select
table_schema,
concat(truncate(sum(data_length)/1024/1024,2),' mb') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'mb') as index_size
from information_schema.tables
group by table_schema
order by data_size desc;

2、查询单个库中所有表磁盘占用大小

-- 查询单个库中所有表磁盘占用大小
select concat(truncate(sum(data_length)/1024/1024,2),'mb') as data_size,
         concat(truncate(sum(max_data_length)/1024/1024,2),'mb') as max_data_size,
         concat(truncate(sum(data_free)/1024/1024,2),'mb') as data_free,
         concat(truncate(sum(index_length)/1024/1024,2),'mb') as index_size
  from information_schema.tables
where table_schema = '你的数据库名';

3、查看数据库中所有表的信息

-- 查看数据库中所有表的信息
select
    concat( table_schema, '.', table_name ) as 'table name',
    table_rows as 'number of rows',
    concat( round( data_length / ( 1024 * 1024 * 1024 ), 6 ), ' g' ) as 'data size',
    concat( round( index_length / ( 1024 * 1024 * 1024 ), 6 ), ' g' ) as 'index size',
    concat( round( ( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 6 ), ' g' ) as 'total' 
from
    information_schema.tables w 
where
    table_schema like '你的数据库名';
    
    ```
    ## 4、单位gb表空间
  ```sql
    # 单位gb表空间
select concat( round( sum( data_length ) / ( 1024 * 1024 * 1024 ), 6 ), 'gb' ) as 'total data size' 
from information_schema.tables 
where table_schema like '你的数据库名';

5、索引空间

 -- 索引空间
select concat( round( sum( index_length ) / ( 1024 * 1024 * 1024 ), 6 ), ' gb' ) as 'total index size' 
from information_schema.tables 
where table_schema like '你的数据库名'; 

三、查看数据库的配置情况

这种能排查数据库是默认配置导致的资源没跑满

show variables like '%connect%';

四、重启数据库

万物回归大法

1、命令

 service mysql start
 service mysql stop
 service mysql restart 

2、报错

如果遇到pid报错,那个文件出现问题删除那个

3、报错2

可能是文件之间的权限不匹配,例如改完一个配置文件,重新上传到的,可能是root权限,但是其他的是有的是777,有的是644,导致数据库起不来。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com