- show status where variable_name in ('Queries','Threads_connected','Threads_running');
Queries:服务器总的查询次数
Threads_connected:客户端连接个数
Threads_running:正在执行的客户端个数status.sh #!/bin/bash while true do mysqladmin -uroot ext|awk '/Queries/{q=$4}/Threads_connected/{c=$4}/Threads_running/{r=$4}END{printf("%d %d %d\n",q,c,r)}' >> status.txt sleep 1 done
- #查看mysql进程的处理情况
show processlist;
需要周期性地调用来查看state状态的值的分布。下面是几个比较影响性能的state值:
1, converting HEAP to MyISAM (查询结果太大时,把结果放在磁盘)
2, create tmp table (创建临时表【如group by时储存中间结果】)
3, Copying to tmp table on disk (把内存临时表复制到磁盘)
4, locked (被其他查询锁住)
5, logging slow query (记录慢查询)processlist.sh 周期性观察脚本 #!/bin/bash while true do mysql -uroot -e 'show processlist\G'|grep State:|uniq -c|sort -rn echo '---' sleep 1 Done
- #使用profile功能,查看查询语句的具体执行时间
show variables like '%profil%'; #查看是否打开了profile功能
set profiling=1; #手工打开profile功能
show profiles; #查看profile列表
show profile for query {id}; #查看具体的某个查询语句的时间。 - 修复数据和索引文件碎片(长期的删除或修改会产生文件空洞),一般半年可操作一次,要在没人做业务的时间段内操作。
optimize table xxx;
alter table xxx engine innodb;
这两种方式都可以,看mysql数据库支持哪种。
MySQL基础运维一
最新推荐文章于 2023-12-27 15:43:42 发布