下面分享大佬的mysql 的巡检命令,比较多的信息都在表格里了
硬件配置信息 | ||
检查项 | 操作命令 | |
服务器名称 | hostname | |
服务器型号 | dmidecode |grep "Product Name" | |
CPU | cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c | |
内存 | cat /proc/meminfo | |
磁盘 | df -h | |
ip地址 | ifconfig -a | |
操作系统 | lsb_release -a或cat /proc/version | |
性能检查 | ||
检查项 | 操作命令 | 备注 |
CPU占用率 | top | CPU每个线程占用率小于80% |
CPU负载 | uptime | CPU负载应小于10 |
内存占用率 | free -m | 内存使用率小于80% |
内存swap使用率 | free -m | swap使用率小于10% |
磁盘使用率 | df -ah | 磁盘使用率小于80% |
磁盘负载 | iostat -xkd 1 | util应在10%以内(或者top命令查看,%wa很高而%us偏低时,可能存在IO瓶颈) |
系统开放端口 | netstat -an|grep LISTEN | 只显示出提供对于服务的端口,无关的端口一律关闭 |
进程检查 | ps aux|more | 关闭占用资源的无用进程 |
数据库巡检 | ||
检查项 | 操作命令 | 备注 |
进程检查 | ps -ef | grep mysqld | 检查port以及datadir |
数据库版本 | select version() | |
超大库检查 | du -sh 每个数据库目录 | |
超大表检查 | show table status | 检查输出后的Rows、Data_length指标,Rows应小于10000000行 |
错误日志 | show variables like '%log_error%'; | 查看文件中是否有ERROR的日志 |
慢查询日志 | show variables like '%slow%'; | 检查慢日志是否开启,若开启,检查慢日志文件中的语句 |
重要参数检查 | show variables like 'back_log%'; | back_log 参数的值指出在MySQL暂时停止响应新请求之前的短时间内多少个请求可以被存在堆栈中。 如果系统在一个短时间内有很多连接,则需要增大该参数的值,该参数值指定到来的TCP/IP连接的侦听队列的大小。不同的操作系统在这个队列大小上有它自 己的限制。 试图设定back_log高于你的操作系统的限制将是无效的。默认值为50。对于Linux系统推荐设置为小于512的整数。 |
show variables like 'max_allowed_packet%'; | 客户端和服务器均有自己的max_allowed_packet变量,因此,如你打算处理大的信息包,必须增加客户端和服务器上的该变量。一般情况下,服务器默认max-allowed-packet为1MB | |
show variables like 'interactive_timeout%'; | 交互式连接超时时间(mysql工具、mysqldump等),参数默认值:28800秒(8小时) | |
show variables like 'wait_timeout%'; | 非交互式连接超时时间,默认的连接mysql api程序,jdbc连接数据库等,参数默认值:28800秒(8小时) | |
show variables like 'skip_name_resolve%'; | 使用该参数后可加快内网地址的请求 | |
show variables like 'max_connections%'; | 最大连接数。max_used_connections / max_connections * 100% (理想值≈ 85%) | |
show variables like 'log_bin%'; | binlog日志开启,能实时记录保存DML操作 | |
show variables like 'expire_logs_days%'; | 让mysql自动清理若干天前的binlog | |
show variables like 'open_files_limit%'; | 文件打开限制数 | |
show variables like 'table_open_cache%'; | 打开表缓存大小 | |
show variables like 'thread_cache_size%'; | 线程池缓存大小 | |
show variables like 'sort_buffer_size%'; | 排序缓冲区大小 | |
show variables like 'join_buffer_size%'; | 内连接缓冲区大小 | |
show variables like 'innodb_buffer_pool_size%'; | InnoDB缓冲池 | |
show variables like 'innodb_file_per_table%'; | InnoDB独立表空间 | |
show variables like 'innodb_open_files%'; | InnoDB打开文件数 | |
show variables like 'innodb_thread_concurrency%'; | InnoDB并发线程 | |
show variables like 'innodb_flush_log_at_trx_commit%'; | InnoDB将缓存中的redo日志回写到日志文件的设置 | |
show variables like 'innodb_log_buffer_size%'; | InnoDB日志缓冲大小 | |
show variables like 'innodb_log_file_size%'; | InnoDB日志文件大小 | |
show variables like 'innodb_log_files_in_group%'; | InnoDB日志文件组 | |
show variables like 'general_log%'; | 日志功能是否开启 | |
show variables like 'log_error%'; | 错误日志位置 | |
show variables like 'slow_query_log%'; | 慢查询日志 | |
show variables like 'long_query_time%'; | 慢查询查询时间超多久会写日志 | |
QPS检查 | 间隔执行 show status like 'queries' | 通过两次的间隔时间做差值,计算QPS |
读写比检查 | show status like 'com_%' | 读请求是com_select; |
当前连接数检查 | show status like '%Threads_connected%' | 此值为当前连接数,应当远小于max_connections |
最大连接数检查 | show status like | 若max_used_connections逼近 |
异常连接查询 | show variables like '%Aborted%' | 检查Aborted_clients以及Aborted_connects值是否正常 |
并发线程查询 | show global status like | 此值应小于10,如果过大,说明并发数太多,存在慢语句。 |
线程缓存池检查 | show status like | threads_created/connections为缓存未命中率,若此值过高,则需要调大thread_cache_size |
运行线程状态查询 | show full processlist; | 查看当前并发 线程是否状态正常 |
InnoDB Buffer Pool检查 | show status like | Innodb_buffer_pool_reads/ |
锁等待检查 | show full processlist; | 检查state列是否存在wait for xxx |
InnoDB死锁检查 | show engine innodb status; | 查看LATEST DETECTED |
InnoDB长事务检查 | show engine innodb status; | 检查TRANSACTIONS输出段,看是否存在ACTIVE时间过长的事务,若存在,则需要关注 |
表缓存检查 | show global status like | 若opened_tables过大,则需要调大 |
查询缓存检查啊 | show variables like | 一般情况下,需要禁用query_cache。 |
临时表检查 | show global status like '%tmp%'; | 如果Created_tmp_tables, |
binlog是否开启 | show variables like 'log_bin' | |
复制检查 | show slave status; | 检查是否正常 |
备份检查 | 检查备份脚本或备份软件是否正常,检查备份文件是否可用 |