Three ways to check the normal running time of MySQL/MariaDB database on Linux - Zhihu

Keywords: MySQL MariaDB Linux Database

Each service has its own command to check the uptime of the service. But you can also use other commands for this.

We all know the purpose of using the uptime command in Linux. It is used for checking Linux system uptime And the time since the system was last started.

The Linux administrator's job is to keep the system running normally.

If you want to check other services on Linux (for example Apache , MySQL, MariaDB, sftp, etc.) how long has it been running and what should I do?

Each service has its own command to check the uptime of the service. But you can also use other commands for this.

Method 1: how to use ps command to check the normal running time of MySQL/MariaDB database on Linux

ps command It means process status. This is one of the most basic commands that shows the details of the process that the system is running.

To do this, you first need to use the pidof command lookup MySQL/MariaDB PID of.

# pidof mysqld | cut -d" " -f1

2412

After getting the PID of MySQL/MariaDB, use the -- etime option in the ps command to get uptime.

  • --etime: the time since the process was started, in the form of [[DD-]hh:]mm:ss.
# ps -p 2412 -o etime

   ELAPSED
2-08:49:30

Alternatively, use the -- lstart option in the ps command to get the uptime of the specified PID.

# ps -p 2412 -o lstart

                STARTED
Sat May 2 03:02:15 2020

MySQL/MariaDB process has been running for 2 days, 03 hours, 02 minutes and 15 seconds.

Method 2: how to use systemctl command to check the normal running time of MySQL/MariaDB database on Linux

systemctl command Used to control the systemd system and service manager.

systemd is a new initialization system and system manager. Now most Linux distributions have adopted systemd instead of the traditional SysVinit manager.

# systemctl status mariadb
//perhaps
# systemctl status mysql

● mariadb.service - MariaDB 10.1.44 database 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) since Sat 2020-05-02 03:02:18 UTC; 2 days ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 2448 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  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)
  Process: 2386 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 2412 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─2412 /usr/sbin/mysqld

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
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.
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.

Method 3: how to use MySQL admin command to check the normal running time of MySQL/MariaDB database on Linux

MySQLAdmin Is the MySQL server command-line program that is installed when the MySQL package is installed.

The MySQL admin client allows you to perform some basic management functions on the MySQL server.

It is used to create database, delete database, set root password, change root password, check MySQL status, verify MySQL function, monitor MySQL process and verify server configuration.

# mysqladmin -u root -pPassword version

mysqladmin Ver 8.42 Distrib 5.7.27, for Linux on x86_64
Copyright (c) 2000, 2019, 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.7.27
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 1 day 10 hours 44 min 13 sec

via: https://www.2daygeek.com/check-mysql-mariadb-database-server-uptime-linux/

Author: Magesh Maruthamuthu Topics: lujun9972 translator: geekpi Checked by: wxy

This paper is composed of LCTT Original compilation, Linux China Honor launch

Posted by kevinritt on Fri, 29 May 2020 17:56:15 -0700