These days I’m trying to develop a BASH script to help me copy quickly my MySQL database from my (live) remote site straight into my PC, where I do all my development work. Right at the top of the script I was writing, I needed a way for the script to figure out if the (development PC‘s) MySQL server (mysqld) was already started and running. And if not, to let me know.
Going through the official MySQL documentation online, it seems the simplest way to find out if mysqld is running is to use the mysqladmin program.
mysqladmin is a client for performing administrative operations.
I tried a few (mysqladmin) commands before I settled on the one that seemed the simplest:
Check whether the server is available. The return status from mysqladmin is 0 if the server is running, 1 if it is not…
Example BASH Script
Find out if MySQL is running or not
In my BASH script, this is how it was used:
... # Check if the MySQL daemon is alive if ! mysqladmin ping > /dev/null 2>&1; then echo "mysqld is dead!" echo "Please start the MySQL server on this machine and try again." exit 1 else echo "mysqld is running, OK." echo fi ...
If you develop exclusively on Linux PCs like I do, this is useful information for you.