xxxxxxxxxx
- Linux, choose:
sudo service mysql status
mysqladmin -u root -p status
/etc/init.d/mysql status
-- Windows, choose:
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqlshow"
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqlshow" -u root mysql
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqladmin" version status proc
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" test
xxxxxxxxxx
import subprocess
def is_mysql_running():
try:
# Run the command to check the MySQL service status
subprocess.check_output(['service', 'mysql', 'status'])
return True
except subprocess.CalledProcessError as e:
# If the command returns a non-zero exit code, MySQL is not running
return False
# Call the function to check if MySQL is running
if is_mysql_running():
print("MySQL is running.")
else:
print("MySQL is not running.")