How to log MySQL downtime If I wanted to see the date, time and length of downtime on a MySQL instance/database, how would I go about doing that?

For example, if I wanted to see if the MySQL database went down at all last week, I could see when it when down and when it came back up – therefore, with a little subtraction I could figure out the downtime.

I am not particular about the method that I get this information, that is just what I thought would be the easiest way to do it. However, I am new to MySQL and am not really sure.
I have made a script that digs through the error log to find the shutdown and startup times for a MySQL server:

######################
##BY: Michael       ##
##Created: 4-1-2016 ##
##Version: 1.01     ##
######################

#####################
######Variables######
#############################################################

#LogFile is where the ErrorLog dumps its filtered error log data
LogFile=/sw/pkg/mysql/admin/logs/shutdowns.log
#Error log holds the raw information from the MySQL Error log filtered by grep.
ErrorLog='grep 'Starting' /var/lib/mysql/'`hostname`'.err'
#OutputFile holds a comma delimited set of values of hostname,shutdown date, shutdown time, startup time
OutputFile=/sw/pkg/mysql/admin/logs/shutdowns_`date +"%Y-%m-%d"`.csv

#############################################################
######Variables######
#####################







##################
######Header######
#############################################################

#Write (Not append) to $LogFile
$ErrorLog &gt; $LogFile
#Writes (Not append) the table headers
echo "hostname,Shutdown_date,Shutdown_time,Startup_time" &gt; $OutputFile

#############################################################
######Header######
##################







################
######Body######
#############################################################

#Do not change variables!
q=0
intholder=-1

#Go line by line in $LogFile. '$i' is the current line (string).
while read i; do
        ((q++))

        #If the line ($i) is a line containing shut-down information then gathers in shut-down information
        if [[ $i =~ "Starting shutdown..." ]]
        then
                shutdowndate=`echo "$i" | grep -Eo '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}'`
                shutdowntime=`echo "$i" | grep -Eo '[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}'`
                ((intholder=$q + 1))
        fi

        #If the line ($i) is a line containing start-up information then gather that information
        if [[ "$intholder" == "$q" ]]
        then
                startuptime=`echo "$i" | grep -Eo '[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}'`
                echo "MySQL instance:`hostname` went down on $shutdowndate at $shutdowntime and started at $startuptime"

                echo "`hostname`,$shutdowndate,$shutdowntime,$startuptime" &gt;&gt; $OutputFile
        fi


#End loop
done &lt;$LogFile

#############################################################
######Body######
################







##################
######Footer######
#############################################################
#       Nada
#############################################################
######Footer######
##################