1

I have tried to change the MySQL Data Directory to a New Location.

Therefore I have changed the MySQL configuration file

/etc/mysql/mysql.conf.d/mysqld.cnf

and the apparmor file

/etc/apparmor.d/usr.sbin.mysqld

Unfortunately it did not work and I got the following error:

mysqld: Can't change dir to '/new/dir/mysql/' (Errcode: 13 - Permission denied)

I reinstalled both mysql and apparmor. Since then not even apparmor does work anymore. I get the following messages:

Error-messages:

root@Server:~# systemctl status apparmor.service
● apparmor.service - LSB: AppArmor initialization
   Loaded: loaded (/etc/init.d/apparmor; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2018-08-24 09:24:24 CEST; 1min 41s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 19955 ExecStart=/etc/init.d/apparmor start (code=exited, status=123)

Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.dict in /etc/apparmor.d/abstractions/nameservice at line 16: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.lib.snapd.snap-confine.real in /etc/apparmor.d/usr.lib.snapd.snap-confine.real at line 11: Could not open '/var/lib/snapd/apparmor/snap-confine'
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.sbin.dovecot in /etc/apparmor.d/abstractions/nameservice at line 16: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Aug 24 09:24:24 Server apparmor[19955]: AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in /etc/apparmor.d/abstractions/winbind at line 13: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml)
Aug 24 09:24:24 Server apparmor[19955]:    ...fail!
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Control process exited, code=exited status=123
Aug 24 09:24:24 Server systemd[1]: Failed to start LSB: AppArmor initialization.
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Unit entered failed state.
Aug 24 09:24:24 Server systemd[1]: apparmor.service: Failed with result 'exit-code'.

I have tried to fix those errors for hours. But now I don't have any clue anymore. Any suggestions what could be the problem?

EDIT: Content of the usr.sbin.mysqld-file

cat /etc/apparmor.d/usr.sbin.mysqld

# vim:syntax=apparmor
# Last Modified: Tue Feb 09 15:28:30 2016
#include <tunables/global>

/usr/sbin/mysqld flags=(complain) {
  #include <abstractions/base>
  #include <abstractions/nameservice>
  #include <abstractions/user-tmp>
  #include <abstractions/mysql>
  #include <abstractions/winbind>

# Allow system resource access
  /sys/devices/system/cpu/ r,
  capability sys_resource,
  capability dac_override,
  capability setuid,
  capability setgid,

# Allow network access
  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

# Allow config access
  /etc/mysql/** r,

# Allow pid, socket, socket lock file access
  /var/run/mysqld/mysqld.pid rw,
  /var/run/mysqld/mysqld.sock rw,
  /var/run/mysqld/mysqld.sock.lock rw,
  /run/mysqld/mysqld.pid rw,
  /run/mysqld/mysqld.sock rw,
  /run/mysqld/mysqld.sock.lock rw,

# Allow execution of server binary
  /usr/sbin/mysqld mr,
  /usr/sbin/mysqld-debug mr,

# Allow plugin access
  /usr/lib/mysql/plugin/ r,
  /usr/lib/mysql/plugin/*.so* mr,

# Allow error msg and charset access
  /usr/share/mysql/ r,
  /usr/share/mysql/** r,

# Allow data dir access
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,

# Allow data files dir access
  /var/lib/mysql-files/ r,
  /var/lib/mysql-files/** rwk,

# Allow keyring dir access
  /var/lib/mysql-keyring/ r,
  /var/lib/mysql-keyring/** rwk,

# Allow log file access
  /var/log/mysql.err rw,
  /var/log/mysql.log rw,
  /var/log/mysql/ r,
  /var/log/mysql/** rw,

  # Site-specific additions and overrides. See local/README for details.
  #include <local/usr.sbin.mysqld>
}
  • See if this helps: askubuntu.com/questions/941070/… – George Udosen Aug 23 '18 at 16:56
  • Trying to put mysql in the complain-mode with sudo aa-complain /usr/sbin/mysqld gives the following message: ERROR: AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in /etc/apparmor.d/abstractions/winbind at line 13: missing an end of line character? (entry: /usr/share/mysql/charsets/*.xml) – jstuhh Aug 23 '18 at 18:45
  • Please look at this line: /etc/apparmor.d/abstractions/winbind at line 13: missing an end of line character – George Udosen Aug 23 '18 at 18:56
  • It is the first line of code: /tmp/.winbindd/pipe rw, – jstuhh Aug 23 '18 at 20:10
  • Run cat /etc/apparmor.d/usr.sbin.mysqld and paste it into your question. There appears to be a syntax error – George Udosen Aug 23 '18 at 20:17
1

A complete removal of all mysql related data was the solution for me to make Apparmor work again.

Additional to removing mysql,

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

I deleted the following folder/files:

rm -rf /etc/apparmor.d/abstractions/mysql 
rm -rf /etc/apparmor.d/cache/usr.sbin.mysqld 
rm -rf /etc/mysql 
rm -rf /var/lib/mysql 
rm -rf /var/log/mysql* 
rm -rf /var/log/upstart/mysql.log* 
rm -rf /var/run/mysqld 
rm -rf ~/.mysql_history

This prompted me the following errors:

    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.auth in /etc/apparmor.d/usr.lib.dovecot.auth at line 18: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.lib.dovecot.dict in /etc/apparmor.d/usr.lib.dovecot.dict at line 16: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14061]: AppArmor parser error for /etc/apparmor.d/usr.sbin.dovecot in /etc/apparmor.d/usr.sbin.dovecot at line 19: Could not open 'abstractions/mysql'
    Aug 24 10:29:37 Server apparmor[14488]: AppArmor parser error for /etc/apparmor.d/sbin.syslog-ng in /etc/apparmor.d/sbin.syslog-ng at line 22: Could not open 'abstractions/mysql'

After I deleted #include <abstractions/mysql> in the corresponding files, I could start Apparmor again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.