mysqlreport安装&使用
mysqlreport安装&使用
2020-12-17
mysql命令行中经常使用下面的指令来获取当前数据库的实时状态:
mysql>show status;
mysql>show innodb status;
但是他们的显示结果不太友好,我们需要更好的更加人性化的分析结果,而不是堆出来一堆数字。mysqlreport是一个第三方的Mysql状态报告工具,它把mysql的show status 和 show innodb status的结果进行一系列的后期处理,让可读性更强,更友好。 下面是mysqlreport的安装过程:
MySQLReport 是用perl语言编写,所以想要运行它首先需要安装perl环境;它还要与MySQL数据库连接,所以还需要安装数据库接口 DBI 和 数据库驱动 DBD-MySQL 。
安装DBI
yum -y install perl-DBI
安装DBD-mysql
yum -y install perl-DBD-MySQL
安装&运行mysqlreport
#下载mysqlreport tgz wget http://pkgs.fedoraproject.org/repo/pkgs/mysqlreport/mysqlreport-3.5.tgz/33a345f5e2c89b083a9ff0423f7fd7b4/mysqlreport-3.5.tgz #解压到目录mysqlreport tar -zxvf download/mysqlreport-3.5.tgz -C mysqlreport/ #使用mysqlreport收集信息 ./mysqlreport --user=root --password=123456 --port 3306 --host=101.133.239.204 --outfile=/usr/local/mysqlreport/report/mysqlreport20201217.txt
mysqlreport20201217.txt内容
MySQL 8.0.21 uptime 8 22:24:56 Thu Dec 17 14:36:11 2020 __ Key _________________________________________________________________ Buffer used 0 of 8.00M %Used: 0.00 Current 1.46M %Usage: 18.24 Write hit 0.00% Read hit 0.00% __ Questions ___________________________________________________________ Total 46.30k 0.1/s Com_ 25.05k 0.0/s %Total: 54.09 DMS 16.45k 0.0/s 35.54 COM_QUIT 6.60k 0.0/s 14.25 -Unknown 1.80k 0.0/s 3.88 Slow 10 s 0 0/s 0.00 %DMS: 0.00 Log: DMS 16.45k 0.0/s 35.54 SELECT 16.43k 0.0/s 35.50 99.88 UPDATE 17 0.0/s 0.04 0.10 INSERT 2 0.0/s 0.00 0.01 REPLACE 0 0/s 0.00 0.00 DELETE 0 0/s 0.00 0.00 Com_ 25.05k 0.0/s 54.09 set_option 24.05k 0.0/s 51.95 show_status 689 0.0/s 1.49 show_variab 43 0.0/s 0.09 __ SELECT and Sort _____________________________________________________ Scan 6.34k 0.0/s %SELECT: 38.59 Range 0 0/s 0.00 Full join 9 0.0/s 0.05 Range check 0 0/s 0.00 Full rng join 0 0/s 0.00 Sort scan 123 0.0/s Sort range 0 0/s Sort mrg pass 0 0/s __ Table Locks _________________________________________________________ Waited 0 0/s %Total: 0.00 Immediate 710 0.0/s __ Tables ______________________________________________________________ Open 360 of 4000 %Cache: 9.00 Opened 488 0.0/s __ Connections _________________________________________________________ Max used 86 of 100 %Max: 86.00 Total 8.16k 0.0/s __ Created Temp ________________________________________________________ Disk table 0 0/s Table 1.44k 0.0/s Size: 16.0M File 9 0.0/s __ Threads _____________________________________________________________ Running 2 of 31 Cached 55 of 100 %Hit: 98.95 Created 86 0.0/s Slow 0 0/s __ Aborted _____________________________________________________________ Clients 3.13k 0.0/s Connects 171 0.0/s __ Bytes _______________________________________________________________ Sent 21.99M 28.5/s Received 10.60M 13.7/s __ InnoDB Buffer Pool __________________________________________________ Usage 74.61M of 128.00M %Used: 58.29 Read hit 99.99% Pages Free 3.42k %Total: 41.71 Data 4.77k 58.18 %Drty: 0.00 Misc 9 0.11 Latched 0.00 Reads 50.57M 65.5/s From file 2.81k 0.0/s 0.01 Ahead Rnd 0 0/s Ahead Sql 0/s Writes 1.47M 1.9/s Flushes 4.66k 0.0/s Wait Free 0 0/s __ InnoDB Lock _________________________________________________________ Waits 4 0.0/s Current 0 Time acquiring Total 204033 ms Average 51008 ms Max 51012 ms __ InnoDB Data, Pages, Rows ____________________________________________ Data Reads 3.23k 0.0/s Writes 23.27k 0.0/s fsync 5.74k 0.0/s Pending Reads 0 Writes 0 fsync 0 Pages Created 2.44k 0.0/s Read 3.14k 0.0/s Written 5.49k 0.0/s Rows Deleted 0 0/s Inserted 393.22k 0.5/s Read 3.84G 5.0k/s Updated 131.08k 0.2/s
InnoDB Lock 可通过以下方式产生
打开一个navicat窗口(窗口1),输入以下命令使得该窗口提交命令后不自动提交
set @@autocommit = 0; #0为不自动提交 1位自动提交 select @@autocommit;
窗口1 执行以下语句
update student set age=14 where id = 00000000000000000001;
在新窗口(窗口3)执行以下语句查看事务表信息表信息
select * from information_schema.INNODB_TRX;
新建窗口(窗口2),输入更改语句,引起所冲突
update student set age=14 where id = 00000000000000000001;
窗口3执行以下语句查看事务表信息表信息,可以看到trx_state为LOCK WAIT。
LOCK WAIT有时间超时设置,超过会回滚
当窗口1 执行命令 commit后事务结束,5545这条记录也会清空,若5447没有超时,也会执行成功,故这条记录也会清空。
参考
[1] MySQL效能监控工具mysqlreport安装和中文说明
[2] MySQLReport
InnoDB Lock