4个用于监视Linux中MySQL性能的有用命令行工具

4个用于监视Linux中MySQL性能的有用命令行工具

有很多工具可以监控MySQL性能并对服务器进行故障排除,但它们并不总是完全匹配MySQL开发人员或管理员的共同需求,或者在某些情况下可能无法工作,例如远程或通过Web监控。

MySQL监控工具
MySQL监控工具

幸运的是,MySQL社区创建了各种开源工具来填补空白。另一方面,通过Web搜索找到这些工具非常困难,这就是我们编译4个命令行工具来监控Linux中MySQL数据库正常运行时间负载性能的原因。

正常运行时间表示自上次关闭或重新启动以来数据库运行和运行的时间。在许多情况下获取有关正常运行时间的信息非常重要,因为它可以帮助系统管理员检查MySQL数据库的状态,MySQL数据库每秒的查询次数,线程,慢查询和许多有趣的统计信息。

1. Mytop

Mytop是我的经典开源之一,免费的基于控制台(非gui)的MySQL数据库监控工具是由Jereme Zawodny使用Perl语言编写的。Mytop在终端中运行,以表格格式显示有关线程,查询,慢查询,正常运行时间,负载等的统计信息,非常类似于Linux 顶级程序。这间接帮助管理员优化和提高MySQl的性能,以处理大量请求并减少服务器负载。

在Linux中安装Mytop Mysql Monitoring
Mytop:Mysql监控

本文参考:https://www.tecmint.com/mysql-performance-monitoring/

对于其他Linux发行版,您可以获取mytop源包并从源代码编译它,如图所示。

#tar -zxvf mytop- <version> .tar.gz
#cd mytop-
#perl Makefile.PL
#make
#make test
#make install

在这个MySQL监控教程中,我们将向您展示如何在各种Linux发行版上安装,配置和使用mytop

请注意,您必须在系统上运行MySQL / MariaDB Server才能安装和使用Mytop

在Linux系统中安装Mytop

要安装Mytop,请运行以下适用于Linux发行版的命令来安装它。

样本输出:

root@iZwz99xibtof6c8lod50rhZ:/# sudo apt install mytop
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  amd64-microcode linux-image-extra-4.4.0-31-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libconfig-inifiles-perl liblist-moreutils-perl
The following NEW packages will be installed:
  libconfig-inifiles-perl liblist-moreutils-perl mytop
0 upgraded, 3 newly installed, 0 to remove and 50 not upgraded.

Progress: [100%] [#######################################################################################################]
Need to get 123 kB of archives.
After this operation, 451 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty/main liblist-moreutils-perl amd64 0.33-1build3 [48.5 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty/main libconfig-inifiles-perl all 2.82-1 [40.0 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty/universe mytop all 1.9.1-1 [34.1 kB]
Fetched 123 kB in 0s (471 kB/s)
Selecting previously unselected package liblist-moreutils-perl.
(Reading database ... 134077 files and directories currently installed.)
Preparing to unpack .../liblist-moreutils-perl_0.33-1build3_amd64.deb ...
Unpacking liblist-moreutils-perl (0.33-1build3) ...
Selecting previously unselected package libconfig-inifiles-perl.
Preparing to unpack .../libconfig-inifiles-perl_2.82-1_all.deb ...
Unpacking libconfig-inifiles-perl (2.82-1) ...
Selecting previously unselected package mytop.
Preparing to unpack .../archives/mytop_1.9.1-1_all.deb ...
Unpacking mytop (1.9.1-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up liblist-moreutils-perl (0.33-1build3) ...
Setting up libconfig-inifiles-perl (2.82-1) ...
Setting up mytop (1.9.1-1) ...
root@iZwz99xibtof6c8lod50rhZ:/#

如何使用Mytop监控MySQL / MariaDB

Mytop需要MySQL / MariaDB登录凭据来监控数据库,并默认使用root用户名连接到服务器。您可以在运行时或在文件中指定用于在命令行上连接数据库服务器的必要选项~/.mytop(为方便起见,如后面所述)。

在出现提示时,只需运行以下命令启动mytop并提供MySQL / MariaDB root用户密码。这将默认连接到测试数据库。

输入MySQL root密码后,您将看到Mytop监控shell,类似于下面的内容。

2. Mtop

mtop(MySQL顶级)是另一个类似的开源,基于命令行的实时MYSQL Server监控工具,用Perl语言编写,显示结果以表格格式很像mytop。mtop监视MySQL查询,这些查询花费了大量的时间来完成并在特定时间后杀死那些长时间运行的查询。

此外,它还使我们能够从命令行界面识别与性能相关的问题,配置信息,性能统计信息和调整相关提示。这两个工具非常相似,但mtop没有主动维护,可能无法在新安装的MySQL版本上运行。

在Linux中安装mtop

mtop预览

有关安装说明的更多信息,请参阅:如何在Linux中安装Mtop(MySQL监控)

3. Innotop

Innotop是一个基于命令行的实时高级调查程序,用于监控在InnoDB引擎下运行的本地和远程MySQL服务器。Innotop包含许多功能,并提供不同类型的模式/选项,这有助于我们监控MySQL性能的各个方面,以找出MySQL服务器的错误。

在Linux中安装Innotop

Innotop预览

有关安装说明的更多信息,请参阅:如何在Linux中安装Innotop(MySQL监控)

4. mysqladmin

mysqladmin是一个默认的命令行MySQL客户端,它预先安装了MySQL包,用于执行管理操作,例如监视进程,检查服务器配置,重新加载权限,当前状态,设置root密码,更改root密码,创建/删除数据库等等。更多。

要检查mysql状态和正常运行时间,请从终端运行以下命令,并确保您必须具有root权限才能从shell执行命令。

sunyang@127:/$ mysqladmin -u root -p version
Enter password:
mysqladmin  Ver 8.42 Distrib 5.5.62, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.5.62-0ubuntu0.14.04.1
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 51 days 13 hours 55 min 47 sec

Threads: 4  Questions: 8714427  Slow queries: 2  Opens: 67359  Flush tables: 1  Open tables: 400  Queries per second avg: 1.955
sunyang@127:/$

有关mysqladmin命令和示例的更多信息,请阅读:Linux中用于MySQL管理的20 mysqladmin命令

结论

如果您正在为自己的工作寻找一个好的监视工具,我推荐mytopinnotop。我曾经依赖于mytop进行日常监控,但现在我转向了innotop,因为它显示了更多的统计信息和信息,包括重要的交易。

本文参考:
https://www.tecmint.com/mysql-performance-monitoring/

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注