Home > Software engineering >  mysql service reappears after kill -9 <pid for mysql>
mysql service reappears after kill -9 <pid for mysql>

Time:05-31

I have mysql installed on Ubuntu18.04. I tried to kill the mysql process with kill -9 but it comes back immediately. Here's example from my terminal output:

root@mysql-image:~# ps aux | grep mysql
mysql      779  0.8 19.2 1166336 188064 ?      Sl   20:06   0:02 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root      1046  0.0  0.1  13144  1060 pts/0    S    20:11   0:00 grep --color=auto mysql
root@mysql-image:~# kill -9 779
root@mysql-image:~# ps aux | grep mysql
mysql     1063 21.5 18.1 1165936 177556 ?      Sl   20:11   0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root      1094  0.0  0.1  13144  1032 pts/0    S    20:11   0:00 grep --color=auto mysql
root@mysql-image:~# kill -9 1063
root@mysql-image:~# ps aux | grep mysql
mysql     1142 21.5 18.1 1165936 177628 ?      Sl   20:12   0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root      1173  0.0  0.1  13144  1084 pts/0    S    20:12   0:00 grep --color=auto mysql

I'm trying to destroy the mysql process in an abrupt way and "unsafe way" as part of an experiment I'm doing. But the kill -9 doesn't seem to permanently shut down the mysql database.

What am I doing wrong?

CodePudding user response:

Normally, systemd will be configured to restart mysql if it unexpectedly terminates, with Restart=on-abort in /usr/lib/systemd/system/mysql.service.

on-abort is explained in: https://unix.stackexchange.com/questions/564443/what-does-restart-on-abort-mean-in-a-systemd-service

You could try making a change to the mysql conf files that keep it from restarting (setting a non-existent user, maybe?). Or you can just do a kill -15 instead, which is treated as an expected termination so won't cause a restart.

  • Related