linux mysql 健康检查_在Linux上检查MySQL/MariaDB数据库正常运行时间的三种方法

9a6a72c7687d10dfcee800249c6be77a.png

我们都知道在 Linux 中使用 uptime 命令的目的。它用于检查 Linux 系统的正常运行时间以及系统上次启动以来运行的时间。

而 Linux 管理员的工作是保持系统正常运行。

如果要检查 Linux 上的其他服务(例如 Apache、MySQL、MariaDB、sftp 等)运行了多长时间,该怎么做?

每个服务都有自己的命令来检查服务的正常运行时间。但是你也可以为此使用其他命令。

方法 1:如何使用 ps 命令在 Linux 上检查 MySQL/MariaDB 数据库的正常运行时间

#pidofmysqld|cut-d" "-f1

2412

获取 MySQL/MariaDB 的 PID 后,请在 ps 命令中使用 --etime 选项获得正常运行时间。

--etime:自进程启动以来经过的时间,形式为 [[DD-]hh:]mm:ss。

#ps-p2412-o etime

ELAPSED

2-08:49:30

或者,在 ps 命令中使用 --lstart 选项来获取指定 PID 的正常运行时间。

#ps-p2412-o lstart

STARTED

SatMay203:02:152020

MySQL/MariaDB 进程已经运行了 2 天 03 小时 02 分 15 秒。

方法 2:如何使用 systemctl 命令在 Linux 上检查 MySQL/MariaDB 数据库的正常运行时间

systemctl 命令用于控制 systemd 系统和服务管理器。

systemd 是新的初始化系统和系统管理器,现在大多数 Linux 发行版都淘汰了传统的 SysVinit 管理器而采用了 systemd。

#systemctlstatus mariadb

或者

#systemctlstatus mysql

●mariadb.service-MariaDB10.1.44database server

Loaded:loaded(/usr/lib/systemd/system/mariadb.service;enabled;vendor preset:disabled)

Drop-In:/etc/systemd/system/mariadb.service.d

└─migrated-from-my.cnf-settings.conf

Active:active(running)sinceSat2020-05-0203:02:18UTC;2days ago

Docs:man:mysqld(8)

https://mariadb.com/kb/en/library/systemd/

Process:2448ExecStartPost=/bin/sh-csystemctlunset-environment _WSREP_START_POSITION(code=exited,status=0/SUCCESS)

Process:2388ExecStartPre=/bin/sh-c[!-e/usr/bin/galera_recovery]&&VAR=||VAR=/usr/bin/galera_recovery;[$?-eq0]&&systemctlset-environment _WSREP_START_POSITION=$VAR||exit1(code=exited,status=0/SUCCESS)

Process:2386ExecStartPre=/bin/sh-csystemctlunset-environment _WSREP_START_POSITION(code=exited,status=0/SUCCESS)

MainPID:2412(mysqld)

Status:"Taking your SQL requests now…"

CGroup:/system.slice/mariadb.service

└─2412/usr/sbin/mysqld

May0321:41:26ns2.2daygeek.com mysqld[2412]:2020-05-0321:41:26140328136861440[Warning]Hostname'1.1.1.1'couldnotbe resolved:…notknown

May0402:00:46ns2.2daygeek.com mysqld[2412]:2020-05-042:00:46140328436418304[Warning]IP address'1.1.1.1'has been resolved to the host name'2…ss itself.

May 04 03:01:31 ns2.2daygeek.com mysqld[2412]: 2020-05-04 3:01:31 140328436111104 [Warning] IP address '1.1.1.1' could not be resolved: Temporary fai…resolution

May 04 04:03:06 ns2.2daygeek.com mysqld[2412]: 2020-05-04 4:03:06 140328136861440 [Warning] IP address '1.1.1.1' could not be resolved: Name or ser… not known

May 04 07:23:54 ns2.2daygeek.com mysqld[2412]: 2020-05-04 7:23:54 140328435189504 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known

May 04 08:03:31 ns2.2daygeek.com mysqld[2412]: 2020-05-04 8:03:31 140328436418304 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known

May 04 08:25:56 ns2.2daygeek.com mysqld[2412]: 2020-05-04 8:25:56 140328135325440 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Hint: Some lines were ellipsized, use -l to show in full.

方法 3:如何使用 MySQLAdmin 命令在 Linux 上检查 MySQL/MariaDB 数据库的正常运行时间

MySQLAdmin 是安装 MySQL 软件包时安装的 MySQL 服务器命令行程序。

MySQLAdmin 客户端允许你在 MySQL 服务器上执行一些基本的管理功能。

它用于创建数据库、删除数据库、设置 root 密码、更改 root 密码、检查 MySQL 状态、验证 MySQL 功能、监视 mysql 进程以及验证服务器的配置。

#mysqladmin-u root-pPassword version

mysqladminVer8.42Distrib5.7.27,forLinuxon x86_64

Copyright(c)2000,2019,Oracleand/orits affiliates.Allrights reserved.

Oracleisa registered trademark ofOracleCorporationand/orits

affiliates.Othernames may be trademarks of their respective

owners.

Serverversion5.7.27

Protocolversion10

ConnectionLocalhostvia UNIX socket

UNIX socket/var/lib/mysql/mysql.sock

Uptime:1day10hours44min13sec

【编辑推荐】

【责任编辑:庞桂玉 TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值