xxxxxxxxxx
import mysql.connector
def check_mysql_status():
try:
# Establishing a connection to the MySQL server
connection = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='your_database'
)
if connection.is_connected():
print("MySQL server is up and running!")
# Closing the connection
connection.close()
except mysql.connector.Error as error:
print(f"Error connecting to MySQL server: {error}")
# Calling the function to check MySQL status
check_mysql_status()
xxxxxxxxxx
sudo service mysql status
# or
ps aux | grep mysql
# connexion:
mysql -u <username> -p <database-name>
xxxxxxxxxx
$ systemctl status mysql
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql; generated)
Active: active (running) since Tue 2021-05-18 13:34:02 CEST; 12s ago
Docs: man:systemd-sysv-generator(8)
Process: 127538 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
Tasks: 33 (limit: 9079)
Memory: 100.8M
CPU: 569ms