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 mariadb.service disabled
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 (/lib/systemd/system/mysql.service; enabled; preset: enabled) Active: active (running) since Tue 2023-02-07 08:39:17 +08; 37min ago Process: 866 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 1068 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 2225) Memory: 360.7M CPU: 4.988s CGroup: /system.slice/mysql.service └─1068 /usr/sbin/mysqld Feb 07 08:39:16 host systemd[1]: Starting MySQL Community Server... Feb 07 08:39:17 host systemd[1]: Started 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 /lib/systemd/systemd-sysv-install. Executing: /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 /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable mysql Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /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 Feb 07 08:39:16 host systemd[1]: Starting MySQL Community Server... Feb 07 08:39:17 host systemd[1]: Started 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.
Comment anonymously. Login not required.
