I'm trying to create a table on a separate directory, like this:

CREATE TABLE `abcdef` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 DATA DIRECTORY='/media/sdc/mysql/';

But it returns the error:

Error in query (1030): Got error 168 from storage engine

In the log it says:

2018-09-17T09:43:22.412636Z 2 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2018-09-17T09:43:22.412686Z 2 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.

The directory /media/sdc/mysql/ exists and I ran the following commands already:

chown -R mysql:mysql /media/sdc/mysql
chmod -R 777 /media/sdc/mysql

I'm using MySQL 5.7.

I have another server running MySQL 5.6 where I created the same table with no issue. In fact I'm replicating it on a new upgraded server.

So why can't MySQL use /media/sdc/mysql?

  • 1
    Does mysqld can access /media/ and /media/sdc/ for reading at least?
    – Akina
    Sep 17 '18 at 10:26
  • On both servers (working and not working), /media and /media/sdc belong to root.
    – leyou
    Sep 17 '18 at 10:29
  • 1
    selinux/ apparmor?
    – danblack
    Sep 17 '18 at 10:36
  • What account the mysqld is running of? is it mysql?
    – Akina
    Sep 17 '18 at 10:45
  • @danblack you are right, it was apparmor, it's working now. If you submit a reply I will accept it.
    – leyou
    Sep 17 '18 at 11:02

apparmor (and selinux) provide additional access controls beyond permissions that can cause these permission denied (13) errors. This occurs generally on systems where data or log files differ from the default.

With apparmor you would add to the bottom of /etc/apparmor.d/local/usr.sbin.mysqld:

/media/sdc/mysql/ r,
/media/sdc/mysql/** rwk, 

And then reload the apparmor service:

service apparmor reload 

If it was selinux:

semanage fcontext -a -t mysqld_db_t "/media/sdc/mysql(/.*)?"
restorecon -Rv /media/sdc/mysql

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.