HowTo: Find out If MySQL Is Running On Linux Or Not

How do I find out if my MySQL server is running or not under Linux / UNIX operating systems?

You can use mysql startup script or mysqladmin command to find out if it is running on Linux. Then you can use ps command and telnet command too (it is not reliable but it works.). mysqladmin is a utility for performing administrative operations. You can also use shell script to monitor MySQL server. You can use mysqladmin as follows:


# mysqladmin -u root -p status

Enter password:
Uptime: 4  Threads: 1  Questions: 62  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 45  Queries per second avg: 15.500

If MySQL serer is running it will display output as above. It displays uptime and number of queries etc. If server is not running then it will dump error as follows
# mysqladmin -u root -p status

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

Under Debian Linux you can type following command to find out if MySQL server is running or not
# /etc/init.d/mysql statusOutput:

/usr/bin/mysqladmin  Ver 8.41 Distrib 4.1.15, for pc-linux-gnu on i486
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          4.1.15-Debian_1-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 4 min 16 sec

Threads: 1  Questions: 66  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 45  Queries per second avg: 0.258

If you are using RedHat of Fedora then you can use following script”
# service mysqld statusOR# /etc/init.d/mysqld statusSee also:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

8 comments… add one
  • Yashpal Jan 15, 2007 @ 11:32

    Also we can use

    mysqladmin -umysql ping

    It says “mysqld is alive” if mysql is running o/w
    prints some messages.

    If it doesn’t work then try:

    mysqladmin -uDB_USERNAME -pDB_USERPASSWORD ping

    Where you have to replace DB_USERNAME and DB_USERPASSWORD with actual values.

    Thanks & Regards,

  • Tony Jan 16, 2013 @ 14:47

    mysqladmin ping > /dev/null 2>&1 && echo RUNNING || echo DOWN

    mysqladmin ping > /dev/null 2>&1 && up=1 || up=0


    Why preffered?
    man mysqladmin
    Check whether the server is available. The return status from mysqladmin
    is 0 if the server is running, 1 if it is not. *****This is 0 even in case of
    an error such as Access denied, because this means that the server is
    running but refused the connection, which is different from the server
    not running.*****

  • anurag Feb 14, 2013 @ 6:01

    start the
    service mysqld start

  • Larry Apr 2, 2014 @ 19:25
    TMP=`mysqladmin -u root -p[password] status 2>&1 | head -n 1 | cut -f1 -d:`
    case ${TMP} in
    Uptime) echo "MySQL is running.";;
    *) echo "MySQL is not running.";;
  • susmitha Jun 14, 2016 @ 13:29

    How we can know whether the database is in running state or not? Can anyone help.

  • Jason Jun 24, 2016 @ 18:06

    None of the above solutions worked in my environment. Here is what I had returned to me:
    mysqladmin: command not found
    /etc/init.d/mysql: No such file or directory
    mysqld: unrecognized service
    mysql: unrecognized service
    /etc/init.d/mysqld: No such file or directory

  • Harinath Oct 17, 2016 @ 11:18

    Simply you can find using below…

    service mysql status

  • bazzilic Oct 10, 2017 @ 4:49

    Could be easily obtained using this query:

    show variables where Variable_name = ‘version_compile_os’

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.