Cheap Tickets to India
Sep 122018
 

Just this morning, someone asked me for the command to check if MySQL (or MariaDB) is running?

I quickly blurted out: Do a top or htop and you should see it.

# top | grep mysqld
26125 mysql  20   0 2618520 193692   9092 S  62.5  2.4 159:29.14 mysqld                                                   
26125 mysql  20   0 2618520 193692   9092 S   1.3  2.4 159:29.18 mysqld

While my answer was not wrong, I quickly realized there were better ways to find out if MySQL (or MariaDB) is running was running on a Linux box (in my case, CentOS 7).

Here are a few ways to determine if MySQL is running on a CentOS 7 or Red Hat 7 Linux box.

# service mariadb status
Redirecting to /bin/systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-08-30 07:59:30 EDT; 1 weeks 4 days ago
 Main PID: 25949 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─25949 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─26125 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pi...

My favorite is the systemctl method since I use it often to check the status of other services like httpd.

$ systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-08-30 07:59:30 EDT; 1 weeks 4 days ago
 Main PID: 25949 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─25949 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─26125 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pi...

Here’s another method to check the status of MySQL server:

$ mysqladmin -u root -p status
Enter password: 
Uptime: 1001300  Threads: 1  Questions: 11923946  Slow queries: 0  Opens: 701  Flush tables: 2  Open tables: 260  Queries per second avg: 11.908

You can always ping it.

# mysqladmin -umysql ping
mysqld is alive

Here’s one more way:

# mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 9.0 Distrib 5.5.60-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version		5.5.60-MariaDB
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/lib/mysql/mysql.sock
Uptime:			11 days 14 hours 32 min 44 sec

Threads: 1  Questions: 11943278  Slow queries: 0  Opens: 701  Flush tables: 2  Open tables: 260  Queries per second avg: 11.910

On a Linux Mint or Ubuntu box, the following command should work:

$ /etc/init.d/mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-09-10 02:13:20 EDT; 19h ago
 Main PID: 2250 (mysqld)
   CGroup: /system.slice/mysql.service
           └─2250 /usr/sbin/mysqld
 Posted by at 1:46 pm

Sorry, the comment form is closed at this time.