Mytop – 在Linux中监控MySQL / MariaDB性能的有用工具

Mytop是一个开源的,MySQLMariaDB数据库的免费监控程序由Jeremy Zawodny使用Perl语言编写。它与最着名的Linux系统监控工具top的外观和感觉非常相似。

Mytop程序提供了一个命令行shell接口,用于监控实时MySQL / MariaDB 线程每秒查询数进程列表数据库性能,并为数据库管理员提供了一个更好地优化服务器以处理高负载的想法。

默认情况下,Mytop工具包含在FedoraDebian / Ubuntu存储库中,因此您只需使用默认的包管理器进行安装即可。

如果您使用的是RHEL / CentOS发行版,则需要启用第三方EPEL存储库来安装它。

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

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

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

$ sudo apt install mytop#Debian / Ubuntu
#yum install mytop#RHEL / CentOS
#dnf install mytop #Fedora 22+
#pacman -S mytop #Arch Linux 
mytop #openSUSE中的#zypper

1. 在Ubuntu18中安装Mytop

安装的命令如下:

sunyang@127:~$ sudo apt install mytop

下面是命令的整个流程

sunyang@127:~$ sudo apt install mytop
[sudo] password for sunyang:
Reading package lists... Done
Building dependency tree
Reading state information... Done
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 0 not upgraded.
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.digitalocean.com/ubuntu/ trusty/main liblist-moreutils-perl amd64 0.33-1build3 [48.5 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu/ trusty/main libconfig-inifiles-perl all 2.82-1 [40.0 kB]
Get:3 http://mirrors.digitalocean.com/ubuntu/ trusty/universe mytop all 1.9.1-1 [34.1 kB]
Fetched 123 kB in 0s (2,381 kB/s)
Selecting previously unselected package liblist-moreutils-perl.
(Reading database ... 95689 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) ...
sunyang@127:~$

2. 如何使用Mytop监控MySQL / MariaDB

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

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

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

sunyang@127:~$ mytop --prompt
Password:

输入root的密码之后出现如下截图信息


MySQL数据库监控

如果要监视特定数据库,请使用-d如下所示的选项。例如,以下命令将监视数据库sun。

#mytop --prompt -d sun
Password:

监控MySQL数据库 sun

如果每个数据库都有特定的管理员(例如tecmint数据库管理员),那么使用数据库用户名和密码进行连接。

#mytop -u tecmint -p password_here -d sun

但是,这具有一定的安全隐患,因为用户的密码是在命令行上键入的,并且可以存储在shell命令历史记录文件中。此文件可由稍后未经授权的人员查看,该人员可能会使用用户名和密码。

为避免出现此类情况的风险,请使用~/.mytop配置文件指定用于连接数据库的选项。此方法的另一个优点是,每次要运行mytop时,也不会输入多个命令行参数。

vim /root/.mytop

host=localhost
db=mysql
delay=5
port=3306
socket=
batchmode=0
color=1
idle=1

当您以root用户身份直接运行mytop时,以及使用sudo前面的命令作为非root sudo用户运行mytop时,将使用此配置文件。

本文参考:https://www.tecmint.com/mytop-mysql-mariadb-database-performance-monitoring-in-linux/

https://cloud.tencent.com/developer/article/1358594

https://www.digitalocean.com/community/tutorials/how-to-use-mytop-to-monitor-mysql-performance

Leave a comment

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