After upgrading to 15.04, I have had lots of fun getting to know systemd. I think I have everything working except I am unable to stop mysql.service; the systemctl command just hangs and mysql just keeps on running. Has anyone else experienced this or might know what's going on?

  • 2
    By default, it nukes the service with SIGKILL after 3 minutes (if the service fails to terminate normally). Probably you'll have to read the configs of mysql.service.
    – Velkan
    Apr 29, 2015 at 11:06
  • 2
    Which version of MySQL are you running? Did you use their native mysql.service script or did you roll your own?
    – Jos
    Apr 30, 2015 at 12:37
  • It's 5.6 which comes out of the official vivid repo. I am using the script that comes with that package. May 2, 2015 at 1:13
  • We had the same problem and filed a bug report.
    – EOLE team
    Jul 8, 2016 at 10:00

6 Answers 6


I had the same problem (upgrade to 15.04, using official files and config).

I had to make the following changes to be able to stop the mysql daemon manually with sytemctl and automatically on system reboot/shutdown:

  1. Make /etc/mysql/debian.cnf readable for the mysql user with

    sudo chgrp mysql /etc/mysql/debian.cnf; sudo chmod 640 /etc/mysql/debian.cnf
  2. Provide a slightly modified mysql.service file:

    sudo cp /lib/systemd/system/mysql.service /etc/systemd/system/
    sudo chmod 755 /etc/systemd/system/mysql.service
  3. Provide an explicit stop command by opening the copied file in an editor:

    sudo nano /etc/systemd/system/mysql.service

    and adding the following line under the [Service] section:

    ExecStop=/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown

    In Nano, use Ctrl+O to save (Linux way!), Ctrl+X to exit.

  4. Make the new service file known to system:

    sudo systemctl daemon-reload
  • My Kubuntu started to freeze during shutdown with A stop job is running for MySQL Community Server [1min 16s / 10min]. This answer resolved the issue, thank you so much. May 20, 2015 at 14:22
  • My 14.10 -> 15.04 upgrade (which moved MySQL 5.5 to 5.6) caused the same issue. Although MySQL 'works' it doesn't shutdown correctly, so Ubuntu hangs on shutdown. Looks like the issue relates to the MySQL version change combined with systemd replacing upstart. This link covers some of the updates to MySQL config to sort out warnings, etc. Starting MySQL always complains about incorrect shutdown too, as systemd just kills the process after 10 minutes, if you can wait that long.
    – Mike
    Jul 2, 2015 at 12:36
  • 1
    Same problem in Debian Jessie / Testing with MySQL 5.6 - fixed thanks to you :)
    – Majenko
    Sep 20, 2015 at 10:43
  • I hate having to do this but I'm so glad it works, thanks Udo! Oct 20, 2015 at 9:14
  • 1
    Worked perfectly for me on Ubuntu 16.04. I was looking at A stop job is running for MySQL Community Server [1min 16s / 10min] every time I shutdown my system. Sep 28, 2016 at 4:43

I had the same problem with Ubuntu 15.10 Desktop and I found way to fix it:

log_error parameter in /etc/mysql/mysql.conf.d/mysqld.cnf was commented out. After uncommenting the parameter, systemd does mysqld shutdown without problems.

  • I had the same problem on Ubuntu LTS 16.04. Only disabling of the error.log was working. Now mysqld writes via the --log-syslog option to the journal. Maybe a reason: the root filesystem was btrfs.
    – ingopingo
    Mar 25, 2017 at 15:46

Your problem is thread_pool_size. If it's much higher than the number of cores/threads, you'll not be able to shutdown properly unless by using mysqladmin shutdown command.

Eg.: You have 2 cores CPU with 4 threads. If you set it 1-4 - it will work fine. If you set it to 16, as advised in many 'high performance' blogs, it'll get pooched.


I had a similar issue with mysql / mariadb failing to stop when instructed by systemd, either on shutdown or called manually with sudo service mysql stop.

In my case I am dual-booting Ubuntu / Windows in UEFI mode, and these OS interpret different hardware time, so both OSs sync against Internet time servers when they start up.

MySQL (and Mariadb) was failing to stop if the hardware time changed while it are running.

You need to defer starting MySQL until after the timesync. Ideally this would be done by inserting a temporal dependency on mysql with After: time-sync but that didn't work for me.

The solution that worked for me (You can replace mysql with mariadb for the same effect):

  1. Disable mysql with sudo systemctl disabled mysql.service

  2. Create a script (ensure it's executable) that will start mysql after some delay /usr/bin/delay_mysql with contents:

    sleep 30s
    /etc/init.d/mysql start
  3. Create a systemd service to run your new script /etc/systemd/system/delay_mysql.service with contents:

    Description=Delay start of MySQL / MariaDB
  4. Register your new service with sudo systemctl enable delay_mysql.service

This will cause your script to run at multi-user levels, which on Ubuntu are 3,4,5.

  • It's solved my problem. However it is very important to note, that before reinstalling MySql you should disable delay_mysql.service, otherwise you got an error.
    – SiGe
    Oct 9, 2017 at 9:42

Just when copying mysql.service you'll have to do a chmod after.

cp /lib/systemd/system/mysql.service /etc/systemd/system/
chmod 755 /etc/systemd/system/mysql.service

in my case it was password mismatch for maintenance user debian-sys-maint between one in /etc/mysql/debian.cnf and one in MySQL database.

This user is used for MySQL shutdown and other functions. After MySQL update it might happened that there is a pass mismatch between file and database. This could also happen if you move your database from one MySQL to another. If you will import all databases and users from other MySQL on different machine you need to re-sync your maintenance user ( debian-sys-maint ) password.

You need to do: check your current password in ubuntu/debian file:

sudo cat /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
host     = localhost
user     = debian-sys-maint
password = n4aSHUP04s1J32X5
socket   = /var/run/mysqld/mysqld.sock
user     = debian-sys-maint
password = n4aSHUP04s1J32X5
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

You can see your password that system will use here: password = n4aSHUP04s1J32X5

Next step is to update MySQL to same password: Log into MySQL:

~$ mysql -u root -p

Type your password to access MySQL

mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'n4aSHUP04s1J32X5';**

After that no more issues with shutdown, no 10 min wait, no issues with installing apps that use this maintenance account like phpmyadmin.

UPDATE: So unfortunately this did not solve the issue. It made it kind of random - sometimes I can stop the service without issue another time it will freeze on service stop.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .