import pymysql


def is_mysql_service_running():
try:
# 尝试连接到MySQL服务
pymysql.connect(host='localhost', user='your_username', password='your_password', database='your_database')
# 如果连接成功,服务正在运行
return True
except pymysql.err.OperationalError:
# 如果连接失败,服务可能没有运行
return False


# 示例调用
if __name__ == '__main__':
if is_mysql_service_running():
print("MySQL service is running.")
else:
print("MySQL service is not running.")