I set up my first Ubuntu Server with Ubuntu 16.04, nginx, php7.0, MariaDB, nextcloud and external DynDNS using this tutorial here: Install Nextcloud 9 on Ubuntu 16.04
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.
I also faced the same issue. You need to set appropriate timeout in the systemd config for mariadb service. Below solved same for me. for ex. When system requires SST it may take long time for mariadb service to come up causing the timeout in systemd.
If you are using systemd 228 or older, then you can execute the following to set an infinite timeout.
sudo tee /etc/systemd/system/mariadb.service.d/timeoutsec.conf <<EOF
[Service]
TimeoutStartSec=0
TimeoutStopSec=0
EOF
sudo systemctl daemon-reload
For other options please refer to https://mariadb.com/kb/en/systemd/
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.
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.
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
The solution for me was to run the following:
sudo killall mysqld
If you are still experiencing this issue, run the command ps -aux | grep 'mysql'
. if anything shows up, just kill it as well.
Finally run:
sudo systemctl restart mysql.service