mysql service fails to start/hangs up - timeout (Ubuntu, MariaDB)

有些话、适合烂在心里 提交于 2019-11-30 11:36:30

In case you are bitten by this bug, the solution is given as a suggestion in the bug report:

  1. echo "/usr/sbin/mysqld { }" > /etc/apparmor.d/usr.sbin.mysqld
  2. apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld
  3. systemctl restart mariadb

Background

If you previously had MySQL installed, it activated an AppArmor profile which is incompatible with MariaDB. apt-get remove --purge only removes the profile, but does not deactivate/unload it. Only manually unloading it lets MariaDB work unhindered by AppArmor.

This last option worked for me (from quazgar). I have Ubuntu 18.10 installed with MariaDB 10.3.13:

$ echo "/usr/sbin/mysqld { }" > /etc/apparmor.d/usr.sbin.mysqld
$ apparmor_parser -v -R /etc/apparmor.d/usr.sbin.mysqld
$ systemctl restart mariadb

I had to use "sudo su" for it to work though.

Moving mysqld to "complain" group was not enough in my case (MariaDB 10.1.21 running on Ubuntu 16.04). I had to fully disable apparmor for mysqld:

sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ 
sudo service apparmor reload
sudo service mysql restart

Now everything works fine.

kerzane

FYI:

In my case neither the solution of Vincent or Lw Bi worked exactly, I needed some further actions.

Disabling the profile through placing a link in /etc/apparmor.d/disable/ simply didn't work, I don't know why.

On the other hand, setting MySQL to complain mode didn't work either immediately.

:~$ sudo aa-complain /usr/sbin/mysqld

Setting /usr/sbin/mysqld to complain mode.

ERROR: /etc/apparmor.d/usr.sbin.mysqld contains no profile

I needed to add the lines:

/usr/sbin/mysqld {
}

to /etc/apparmor.d/usr.sbin.mysqld, and then I could set it to complain mode successfully.

Long question for nothing... Never heard of AppArmor but it was the reasen. The answer here fixed it. Don't care about apparmor's ERROR the profile wouldn't exist.

sudo aa-status shows you what apparmor is doing; what actually has an enforced policy, versus what's just set to complain.

sudo apt-get install apparmor-utils adds a few commands that make the apparmor profiles easier to deal with, such as...

sudo aa-complain /usr/sbin/mysqld turns the profile from "enforce" to complain. (aa-enforce turns it back.)

Once that's done, sudo service apparmor reload restarts apparmor, and voila... sudo /etc/init.d/mysql start works, and the server stays up.

Please note that since 10.1.10, MariaDB uses systemd to start the service. If you have tried MYSQLD_STARTUP_TIMEOUT and it has not worked, you are probably using this or a later version. The /etc/init.d/mysql script is no longer used, so MYSQLD_STARTUP_TIMEOUT has no effect.

You need to find your mariadb.service file. In our case, it did not contain a timeout so the MariaDB default was being used. Just add:

TimeoutStartSec = 0

In the [Service] section, and it will never time out.

It would be a good idea to create your own config file containing this so it doesn't get overwritten by later re-installs.

On ubuntu 18.04, you will fine this file in

/lib/systemd/system/mariadb.service

Put your own file in

/etc/systemd/system/mariadb.service.d

Remember to run systemctl daemon-reload after adding the timeout somewhere (and maybe check /var/log/syslog to see if the reload was successful), otherwise your time out will be ignored.

Run the following commands:

sudo dpkg --configure -a
sudo service mysql start

This is what worked for me:

The correction didn't work for me.

$ sudo aa-complain /usr/sbin/mysqld Setting /usr/sbin/mysqld to complain mode.

ERROR: /etc/apparmor.d/usr.sbin.mysqld contains no profile So I disabled the profile (with aa-disable which seems to be equivalent to plutocrat's solution)

$ sudo aa-disable /usr/sbin/mysqld Disabling /usr/sbin/mysqld. I disabled mysqld-akonadi and mysqld-digikam as well.

An apparmor reload was not enough, so I had to reboot and mariadb started perfectly well.

Source: https://askubuntu.com/a/964928/106100

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!