Controlling the MySQL or MariaDB service is the fastest way to recover from outages, apply configuration changes, and schedule maintenance without guessing whether the database daemon is actually running.
On most modern Linux systems, the database server runs as the mysqld daemon under systemd, which exposes a unit such as mysql.service, mariadb.service, or mysqld.service. The systemctl command is the primary interface for starting, stopping, restarting, and checking health, with status output also showing recent log lines from the unit.
Service names and unit aliases vary by distribution and package, so confirming the exact unit name prevents “Unit not found” errors. Restarting the service terminates existing database connections, and disabling a unit only changes boot-time behavior without stopping a currently running daemon, so maintenance windows and application impact still matter.
Steps to manage MySQL/MariaDB database in Linux:
- Identify the installed database service unit name.
$ systemctl list-unit-files --type=service | grep --extended-regexp '^(mysql|mariadb|mysqld)\.service' mysql.service enabled enabled
Use the unit name shown on the left in later commands.
- Check the status of the database service.
$ sudo systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled) Active: active (running) since Mon 2025-12-29 10:59:07 UTC; 4s ago Process: 958 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 966 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 9396) Memory: 365.6M (peak: 381.2M) CPU: 348ms CGroup: /system.slice/mysql.service └─966 /usr/sbin/mysqld Dec 29 10:59:07 host systemd[1]: Starting mysql.service - MySQL Community Server... Dec 29 10:59:07 host systemd[1]: Started mysql.service - MySQL Community Server.Replace mysql with mariadb or mysqld when that is the unit name on the host.
Some MariaDB packages expose mysql.service as a compatibility alias.
- Stop the database service.
$ sudo systemctl stop mysql
Stopping the service drops active connections and can break applications until the service starts again.
- Start the database service.
$ sudo systemctl start mysql
- Restart the database service.
$ sudo systemctl restart mysql
Restarting interrupts active sessions and can cause transient errors in clients during the restart window.
- Disable the database service from starting on system boot.
$ sudo systemctl disable mysql Synchronizing state of mysql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable mysql Removed "/etc/systemd/system/multi-user.target.wants/mysql.service".
disable changes boot behavior only, so a running service remains running until a separate stop.
Replace mysql with mysqld for RedHat-based platforms.
- Enable the database service to start on system boot.
$ sudo systemctl enable mysql Synchronizing state of mysql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable mysql Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /usr/lib/systemd/system/mysql.service.
- View recent unit logs when the service shows failed or exits unexpectedly.
$ sudo journalctl --unit=mysql.service --no-pager --lines=50 Dec 29 10:59:07 host systemd[1]: Starting mysql.service - MySQL Community Server... Dec 29 10:59:07 host systemd[1]: Started mysql.service - MySQL Community Server. Dec 29 10:59:26 host systemd[1]: Stopping mysql.service - MySQL Community Server... ##### snipped #####
Replace mysql.service with the unit discovered earlier, such as mariadb.service or mysqld.service.
- Verify the service is currently running.
$ systemctl is-active mysql active
- Verify the service start-on-boot setting.
$ systemctl is-enabled mysql enabled
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
