一、查看后台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,导致数据库起不来。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论