执行mysqld --initialize-insecure错误:"mysqld: Can't create directory '/data/3308/data/' (Errcode: 13 ...

执行

mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/usr
mysqld: Can't create directory '/data/3308/data/' (Errcode: 13 - Permission denied)
mysqld: Can't create directory '/data/3308/data/' (Errcode: 17 - File exists)

1.查看日志

journalctl -xe

终端输出结果:

apparmor="DENIED" operation="mkdir" profile="/usr/sbin/mysqld" name="/data/3307/data/" pid=27174 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

其他相关错误

apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/data/3307/my.cnf" pid=29707 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=108 ouid=108

说明: apparmor 授权失败.

#文件路径 /etc/apparmor.d/usr.sbin.mysqld
vim /etc/apparmor.d/usr.sbin.mysqld
# 默认配置
# Allow data dir access
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,
# 添加如下
#'r' (read), 'w' (write), 'm' (memory map as executable), 'k' (file locking), and 'l' (creation hard links)
  /data/3308/data/ rw,
  /data/3308/data/** rwk,

3.重启apparmor

service apparmor restart

4.如果出现 [ERROR] Can't change data directory owner to mysql