1

This question already has an answer here:

I am attempting to relocate the database directory for my mysql installation to a newly install ssd.

Configuration:

Ubuntu 16.04 mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper

I modified /etc/mysql/my.cnf to include a new database dir:

datadir = /mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql

Now in running sudo service mysql start it brings up a permissions error:

mysqld[9002]: mysqld: Can't change dir to '/mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql/' (Errcode: 13 - Permission denied)

I have run both recursive chmod and chown commands on the new directory to match it up and the stat readout now shows as follows:

$ stat /var/lib/mysql
  File: '/var/lib/mysql'
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 812h/2066d  Inode: 13381090    Links: 8
Access: (0700/drwx------)  Uid: (  127/   mysql)   Gid: (  134/   mysql)
Access: 2016-06-23 09:42:37.687378790 -0700
Modify: 2016-06-23 09:46:04.679025933 -0700
Change: 2016-06-23 09:46:04.679025933 -0700
 Birth: -

$ stat /mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql
  File: '/mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql'
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 820h/2080d  Inode: 3276801     Links: 3
Access: (0700/drwx------)  Uid: (  127/   mysql)   Gid: (  134/   mysql)
Access: 2016-06-23 09:45:16.190998487 -0700
Modify: 2016-06-22 18:37:37.707197266 -0700
Change: 2016-06-23 09:45:16.190998487 -0700
 Birth: -

I also modified /etc/apparmor.d/usr.sbin.mysqld to

# Allow data dir access
#  /var/lib/mysql/ r,
#  /var/lib/mysql/** rwk,
/mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql/ r,
/mnt/5abeaa6e-7536-4213-bb3e-97aa9a81be16/mysql/** rwk,

Any ideas would be appreciated.

marked as duplicate by NGRhodes, Videonauth, user117103, Eric Carvalho, user.dz Jun 24 '16 at 3:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

According to this site, you need to edit some configuration and run a few commands to complete the setup.

Add the following to /etc/apparmor.d/usr.sbin.mysqld:

/NEWSQLPATH/ r,
/NEWSQLPATH/** rwk,

Then run:

sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
sudo /etc/init.d/apparmor reload

You can also add this to /etc/apparmor.d/tunables/alias:

alias /var/lib/mysql/ -> /newpath/,

(The commas at the ends of the lines are important.)

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