解决ERROR 1030 (HY000): Got error 168 from storage engine apparmor

建表时指定另外一个目录,结果出错:

mysql>  create table t1 (id int primary key,n varchar(10)) data directory='/home/mysql/data';
ERROR 1030 (HY000): Got error 168 from storage engine

在error log中有这样的提示:

2020-01-16T02:29:45.360317Z 2 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2020-01-16T02:29:45.360400Z 2 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.

以为是mysqld的权限不对,改了也没有用:

mysql> system sudo -u mysql touch  /home/mysql/data/a
mysql>  create table t1 (id int primary key,n varchar(10)) data directory='/home/mysql/data';
ERROR 1030 (HY000): Got error 168 from storage engine

到处搜索,发现是apparmor惹得祸,

# aa-status| grep mysql
   /usr/sbin/mysqld
   /usr/sbin/mysqld (15007) 

修改配置文件把相应的目录加上即可: /etc/apparmor.d/usr.sbin.mysqld

你可能感兴趣的:(MySQL)