Where is systemd script for mysql.service located?

Solution 1:

For units defined in static files you could use systemctl status, with the information outputed issuing that command, you will be able to see its location.

For example:

# systemctl  status sshd
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-10-31 17:01:01 UTC; 1 weeks 0 days ago
 Main PID: 283 (sshd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/sshd.service
           └─290 /usr/bin/sshd -D

Note that the tab command could be helpful here.

Therefore, in my system the systemd services are placed under /usr/lib/systemd/. Please, note that there could be folders in that location.

Another way is to use the find command in that specific location to find a service:

# find /usr/lib/systemd/ | grep -i mysql

I hope that helps ;)

Solution 2:

The default location for systemd init script is:

/lib/systemd/system

But the preferred way to modify them is to create a custom script in:

/etc/systemd/system

scripts in the latter folder override the script in the former location.

Solution 3:

In your particular case it's probably because MySQL doesn't have a systemd service file, but only a SystemV init script in /etc/init.d/mysql. You do have to use systemctl or service to control it though. Running /etc/init.d/mysql stop makes systemd thinks it crashed and restarts it.

Not sure if the newer Ubuntu's do this too, but older ones definitely.