我不得不停止 mysql 服务,删除/var/lib/mysql
,然后使用远程服务器的 副本重新创建它/var/lib/mysql
。如此鲁莽的行动是为了……快速“导入”?……一个非常庞大的数据库。
现在由于 apparmor,我无法重新启动 mysql,这是我第一次知道这个问题。
当尝试再次启动 mysql 服务时,我看到的是:
developer@developer-Inspiron-5559:~$ sudo service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
developer@developer-Inspiron-5559:~$ journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
ene 02 18:05:34 developer-Inspiron-5559 systemd[1]: mysql.service: Unit entered failed state.
ene 02 18:05:34 developer-Inspiron-5559 systemd[1]: mysql.service: Failed with result 'exit-code'.
ene 02 18:05:35 developer-Inspiron-5559 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
ene 02 18:05:35 developer-Inspiron-5559 systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
ene 02 18:05:35 developer-Inspiron-5559 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
ene 02 18:05:35 developer-Inspiron-5559 audit[23831]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23831/status" pid=23831 comm="mysqld" requested_mask="r" denied_mask="r"
ene 02 18:05:35 developer-Inspiron-5559 audit[23831]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=23831 comm="mysqld" requested_mask="r" denied_m
ene 02 18:05:35 developer-Inspiron-5559 audit[23831]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23831/status" pid=23831 comm="mysqld" requested_mask="r" denied_mask="r"
ene 02 18:05:35 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934335.367:51): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23831/status" pid=23831 comm="mysqld" r
ene 02 18:05:35 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934335.367:52): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=23831 comm="my
ene 02 18:05:35 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934335.367:53): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23831/status" pid=23831 comm="mysqld" r
ene 02 18:05:36 developer-Inspiron-5559 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
ene 02 18:06:03 developer-Inspiron-5559 sudo[23927]: developer : TTY=pts/18 ; PWD=/home/developer ; USER=root ; COMMAND=/usr/sbin/service mysql start
ene 02 18:06:03 developer-Inspiron-5559 sudo[23927]: pam_unix(sudo:session): session opened for user root by (uid=0)
ene 02 18:06:05 developer-Inspiron-5559 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
ene 02 18:06:05 developer-Inspiron-5559 systemd[1]: mysql.service: Unit entered failed state.
ene 02 18:06:05 developer-Inspiron-5559 systemd[1]: mysql.service: Failed with result 'exit-code'.
ene 02 18:06:05 developer-Inspiron-5559 sudo[23927]: pam_unix(sudo:session): session closed for user root
ene 02 18:06:06 developer-Inspiron-5559 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
ene 02 18:06:06 developer-Inspiron-5559 systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
ene 02 18:06:06 developer-Inspiron-5559 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
ene 02 18:06:06 developer-Inspiron-5559 audit[23982]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23982/status" pid=23982 comm="mysqld" requested_mask="r" denied_mask="r"
ene 02 18:06:06 developer-Inspiron-5559 audit[23982]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=23982 comm="mysqld" requested_mask="r" denied_m
ene 02 18:06:06 developer-Inspiron-5559 audit[23982]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23982/status" pid=23982 comm="mysqld" requested_mask="r" denied_mask="r"
ene 02 18:06:06 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934366.079:54): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23982/status" pid=23982 comm="mysqld" r
ene 02 18:06:06 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934366.079:55): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=23982 comm="my
ene 02 18:06:06 developer-Inspiron-5559 kernel: audit: type=1400 audit(1514934366.079:56): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/23982/status" pid=23982 comm="mysqld" r
ene 02 18:06:06 developer-Inspiron-5559 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
那么,灾难发生后,我该如何让 apparmor 再次允许 mysql 访问该目录?
编辑也尝试过(按照建议神谕) 这个:
sudo nano /etc/apparmor.d/local/usr.sbin.mysqld
内容:
# Site-specific additions and overrides for usr.sbin.mysqld.
# For more details, please see /etc/apparmor.d/local/README.
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
保存后...
$ sudo service apparmor reload
$ sudo service mysql restart