我们都知道,在MySQL中。能够使用mysqladmin命令的extended-status选项来查看MySQL的执行状态,比方获取我们经常关注的几个值:
# mysqladmin -uroot -proot ext |grep "Questions|Queries|Innodb_rows|Com_select |Com_insert |Com_update |Com_delete " | Com_delete | 26750 | | Com_insert | 347420 | | Com_select | 1341126 | | Com_update | 454425 | | Innodb_rows_deleted | 26590 | | Innodb_rows_inserted | 347416 | | Innodb_rows_read | 2964050 | | Innodb_rows_updated | 695605 | | Queries | 2304578 | | Questions | 2259777 |但这样得到的数值都累计的。假设想了解当前的状态。则须要进行一次差值计算。而庆幸的是,这个client工具提供了两个參数,这样就能实时的得到当前数据库的相关參数值:
-i, --sleep=# Execute commands again and again with a sleep between,单位是秒
-r, --relative Show difference between current and previous values when
used with -i. Currently works only with extended-status.
# mysqladmin -uroot -proot ext -i 1 -r |grep "Questions|Queries|Innodb_rows|Com_select |Com_insert |Com_update |Com_delete " | Com_delete | 26750 | | Com_insert | 347420 | | Com_select | 1341129 | | Com_update | 454425 | | Innodb_rows_deleted | 26590 | | Innodb_rows_inserted | 347416 | | Innodb_rows_read | 2964050 | | Innodb_rows_updated | 695605 | | Queries | 2304592 | | Questions | 2259791 |这样就得到了MySQL当前数据库每秒中相应值。非常直观,这个命令在RHEL 6.4 x86_64系统上能够正常使用。但在SuSE linux 11sp1 x86_64系统中,却是不准确的。即使用-i(或--sleep=)指定刷新的秒数,但事实并不是如此。
在測试中。常常是指定了--sleep=1,但显示结果却是大概1分多钟刷新一次,很奇怪。但在使用strace跟踪发现了原因:
# strace mysqladmin -uroot -proot ext -i 1 -r |grep "Questions|Queries|Innodb_rows|Com_select |Com_insert |Com_update |Com_delete " execve("/usr/bin/mysqladmin", ["mysqladmin", "-uroot", "-proot", "ext", "-i", "1", "-r"], [/* 59 vars */]) = 0 brk(0) = 0x62a000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0c036fe000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/usr/lib64/mysql/tls/x86_64/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/mysql/tls/x86_64", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory) open("/usr/lib64/mysql/tls/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/mysql/tls", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory) open("/usr/lib64/mysql/x86_64/libmysqlclient.so.15", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/usr/lib64/mysql/x86_64", 0x7fffbb00c0f0) = -1 ENOENT (No such file or directory) open("/usr/lib64/mysql/libmysqlclient.so.15", O_RDONLY) = 3 read(3, "177ELF211 3 >