This Code work well
#!/bin/bash
Check MySQL server status
service_status=$(sudo /etc/init.d/mysqld status)
If the service is not running, restart it
if [[ $service_status == "stopped" ]]; then
echo "MySQL server is down. Restarting..."
sudo /etc/init.d/mysqld start
# Check the status again after attempting to start
if [[ $(sudo /etc/init.d/mysqld status) == *"running"* ]]; then
echo "MySQL server restarted successfully."
else
echo "Failed to restart MySQL server."
fi
else
echo "MySQL server is running."
fi