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. A quick status check also shows recent startup failures and restart loops.

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 affects boot-time behavior unless combined with --now to stop the service immediately.

Steps to manage MySQL/MariaDB service with systemctl in Linux:

  1. 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.

  2. 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.

  3. Stop the database service.
    $ sudo systemctl stop mysql

    Stopping the service drops active connections and can break applications until the service starts again.

  4. Start the database service.
    $ sudo systemctl start mysql
  5. Restart the database service.
    $ sudo systemctl restart mysql

    Restarting interrupts active sessions and can cause transient errors in clients during the restart window.

  6. Disable the database service from starting on boot.
    $ sudo systemctl disable --now 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 unless combined with --now.

  7. Enable the database service to start on boot.
    $ sudo systemctl enable --now 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.
  8. 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.

  9. Verify the service is currently running.
    $ systemctl is-active mysql
    active
  10. Verify the service start-on-boot setting.
    $ systemctl is-enabled mysql
    enabled