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

系统 Linux MariaDB
如果要检查 Linux 上的其他服务(例如 Apache、MySQL、MariaDB、sftp 等)运行了多长时间,该怎么做?每个服务都有自己的命令来检查服务的正常运行时间。但是你也可以为此使用其他命令。

[[328227]]

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

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

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

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

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

rocess-monitoring/" class="ext" rel="external nofollow" target="_blank">ps 命令的意思是进程状态process status。这是最基本的命令之一,它显示了系统正在运行的进程的详细信息。

为此,你首先需要使用 rocess-id-pid-ppid-linux/" class="ext" rel="external nofollow" target="_blank">pidof 命令查找 MySQL/MariaDB 的 PID。

  1. # pidof mysqld | cut -d" " -f1
  2.  
  3. 2412

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

  • --etime:自进程启动以来经过的时间,形式为 [[DD-]hh:]mm:ss
  1. # ps -p 2412 -o etime
  2.  
  3. ELAPSED
  4. 2-08:49:30

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

  1. # ps -p 2412 -o lstart
  2.  
  3. STARTED
  4. Sat May 2 03:02:15 2020

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

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

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

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

  1. # systemctl status mariadb
  2. 或者
  3. # systemctl status mysql
  4.  
  5. mariadb.service - MariaDB 10.1.44 database server
  6. Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  7. Drop-In: /etc/systemd/system/mariadb.service.d
  8. └─migrated-from-my.cnf-settings.conf
  9. Active: active (running) since Sat 2020-05-02 03:02:18 UTC; 2 days ago
  10. Docs: man:mysqld(8)
  11. https://mariadb.com/kb/en/library/systemd/
  12. Process: 2448 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  13. Process: 2388 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=/usr/bin/galera_recovery; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  14. Process: 2386 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  15. Main PID: 2412 (mysqld)
  16. Status: "Taking your SQL requests now…"
  17. CGroup: /system.slice/mariadb.service
  18. └─2412 /usr/sbin/mysqld
  19.  
  20. May 03 21:41:26 ns2.2daygeek.com mysqld[2412]: 2020-05-03 21:41:26 140328136861440 [Warning] Host name '1.1.1.1' could not be resolved: not known
  21. May 04 02:00:46 ns2.2daygeek.com mysqld[2412]: 2020-05-04 2:00:46 140328436418304 [Warning] IP address '1.1.1.1' has been resolved to the host name '2…ss itself.
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
  28. 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 进程以及验证服务器的配置。

  1. # mysqladmin -u root -pPassword version
  2.  
  3. mysqladmin Ver 8.42 Distrib 5.7.27, for Linux on x86_64
  4. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  5.  
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9.  
  10. Server version 5.7.27
  11. Protocol version 10
  12. Connection Localhost via UNIX socket
  13. UNIX socket /var/lib/mysql/mysql.sock
  14. Uptime: 1 day 10 hours 44 min 13 sec

 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2019-01-15 14:00:59

Linux服务器命令

2022-08-19 11:17:09

Linux

2015-12-11 09:24:38

加密数据Linux

2010-07-29 09:56:45

Flex数据库

2010-11-19 14:51:09

Oracle数据库关闭

2022-11-04 09:09:54

Linux服务器

2019-06-06 09:20:31

2021-06-24 10:28:19

uptimed命令Linux

2022-05-09 07:20:10

监控项目工具

2009-07-22 11:33:14

JDBC连接Sybas

2021-05-10 07:30:07

Linux统计程序

2021-05-11 11:52:23

Linuxtime命令

2021-08-11 11:02:17

Linuxtime命令

2023-02-21 14:58:12

间序列周期数据集

2009-10-28 18:00:34

Visual C#数据

2022-11-18 15:09:29

2017-12-21 09:29:47

网络运行实践

2014-04-01 10:38:09

Linux操作系统

2022-12-30 08:08:30

2022-05-31 16:00:46

Go 编程语言复制文件Go 标准库
点赞
收藏

51CTO技术栈公众号