您好,欢迎来到99网。
搜索
您的当前位置:首页mysql数据库运行性能检查脚本

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

来源:99网
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;

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务