mysql数据库运行性能检查脚本

只针对mysql 5.6.8以上版本
select version();
use information_schema;
#查询所有数据库参数
show VARIABLES;

#查询数据库最大连接数
show variables like '%max_connections%';

#查询当前数据库连接数
show full processlist;

#单表记录数超过1000W的数据库查询
select table_schema,table_name,table_rows
from information_schema.tables where table_rows >=10000000 ;

#查看数据库所有索引
SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum';

#查看某一表索引
SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum' and a.table_name like '%t_sys_base_user%';
SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum' and a.table_name ='t_sys_base_user';

#数据库表空间大于1T检查
SELECT table_schema as 'Database',
       table_name,
    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;

#数据文件存放路径
show variables like 'datadir';

#数据库文件占用磁盘空间检查
du -h /data/mysql/data/

#告警 mysql错误日志存放路径
show variables where variable_name = 'log_error';


#mysql数据库监控:
#慢查询日志
show variables WHERE  variable_name = 'slow_query_log_file';
 
#查询写入慢查询日志的时间阈值
show variables WHERE  variable_name = 'long_query_time';
 
#查询哪个sql消耗资源情况
select Id,User,Host,db,Time,Info from information_schema.`PROCESSLIST` where info is not null;

#查询是否锁表
show OPEN TABLES where In_use > 0;

#查看正在等待锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

#查询所有数据的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

#查看指定数据库的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='uum';

#查看指定数据库的某个表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='uum' and table_name='t_sys_base_user';


Linux下命令:free –m    系统实际内存
•used=total-free 即 total=used+free
•实际内存占用:used-buffers-cached 即 total-free-buffers-cached
•实际可用内存:buffers+cached+free
•total 内存总数: 128
•used 已经使用的内存数: 119
•free 空闲的内存数: 8
•shared 当前已经废弃不用,总是0
•buffers Buffer Cache内存数: 1
•cached Page Cache内存数: 22
•-buffers/cache 的内存数:95 (等于第1行的 used - buffers - cached)
•+buffers/cache 的内存数: 32 (等于第1行的 free + buffers + cached)
•SWAP 虚拟内存

Linux下命令:iostat 1 1   IO使用情况
avg-cpu: 总体cpu使用情况统计信息,对于多核cpu,这里为所有cpu的平均值
Device: 各磁盘设备的IO统计信息
Device: 以sdX形式显示的设备名称
•tps: 每秒进程下发的IO读、写请求数量
•KB_read/s: 每秒读扇区数量(一扇区为512bytes)
•KB_wrtn/s: 每秒写扇区数量
•KB_read: 取样时间间隔内读扇区总数量
•KB_wrtn: 取样时间间隔内写扇区总数量

Linux下命令:vmstat 2 2000    虚拟内存
Procs(进程):
r: 运行队列中进程数量
b: 等待IO的进程数量
Memory(内存):
swpd: 使用虚拟内存大小
free: 可用内存大小
buff: 用作缓冲的内存大小
cache: 用作缓存的内存大小
Swap:
si: 每秒从交换区写到内存的大小
so: 每秒写入交换区的内存大小
IO:(现在的Linux版本块的大小为1024bytes)
bi: 每秒读取的块数
bo: 每秒写入的块数
 系统:
in: 每秒中断数,包括时钟中断。
cs: 每秒上下文切换数。
CPU(以百分比表示):
us: 用户进程执行时间(user time)
sy: 系统进程执行时间(system time)
id: 空闲时间(包括IO等待时间)
wa: 等待IO时间
   
Linux下  命令:top      cpu使用情况   
PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位1/100秒
COMMAND — 进程名称(命令名/命令行)

# 检查mysql数据库各个表空间的大小(数据空间和索引空间以及总和)
    select TABLE_NAME,
            concat(truncate(data_length/1024/1024/1024, 2), 'GB') as data_size,
            concat(truncate(index_length /1024/1024/1024, 2), 'GB') as index_size,
            truncate(data_length/1024/1024/1024, 2)+  truncate(index_length /1024/1024/1024, 2)
    from information_schema.tables where TABLE_SCHEMA = 'smapuum'  order by data_length desc;








转载于:https://www.cnblogs.com/pdspkj/p/10082294.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值