Unable to change the MySQL data directory
<p>I'm trying to change the data directory of my MySQL database from the default location /var/lib/mysql to a new path which in my case is /home/dev/Desktop/iiab/db/mysql.</p>

<p>I have tried following the answer provided by Victor in the following post:
<a href="https://stackoverflow.com/questions/1795176/how-to-change-mysql-data-directory">How to change MySQL data directory?</a>
(I have also edited the alias file as per the instruction from mak in the comments on Victor's answer). </p>

<p>BUT, I am getting the following terminal error when trying to start MySQL again: </p>

<pre><code>mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
</code></pre>

<p>When inspecting the log file using below command</p>

<pre><code>tail -f /var/log/mysql/error.log
</code></pre>

<p>It shows the following:</p>

<pre><code>2016-05-23T13:43:11.608141Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-05-23T13:43:11.608234Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-05-23T13:43:11.608252Z 0 [ERROR] Failed to initialize plugins.
2016-05-23T13:43:11.608260Z 0 [ERROR] Aborting

2016-05-23T13:43:11.608297Z 0 [Note] Binlog end
2016-05-23T13:43:11.608416Z 0 [Note] Shutting down plugin 'MyISAM'
2016-05-23T13:43:11.608469Z 0 [Note] Shutting down plugin 'CSV'
2016-05-23T13:43:11.609124Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
</code></pre>

<p>My my.cnf file looks as follows (I omitted the initial comments ##):</p>

<pre><code>!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

[mysqld]
datadir=/home/dev/Desktop/iiab/db/mysql
socket=/home/dev/Desktop/iiab/db//mysql.sock
</code></pre>

<p>My /etc/apparmor.d/usr.sbin.mysqld file looks as follows (I only included the parts which were affected by the instructions i.e. replace var/lib/mysql with the new path).</p>

<pre><code># Allow data dir access
  /home/dev/Desktop/iiab/db/mysql/ r,
  /home/dev/Desktop/iiab/db/mysql/** rwk,

# Allow data files dir access
  /home/dev/Desktop/iiab/db-files/ r,
  /home/dev/Desktop/iiab/db-files/** rwk,

# Allow keyring dir access
  /home/dev/Desktop/iiab/db-keyring/ r,
  /home/dev/Desktop/iiab/db-keyring/** rwk,
</code></pre>

<p>My /etc/apparmor.d/tunables/alias file looks as follows (I omitted initial comments ##):</p>

<pre><code># Or if mysql databases are stored in /home:
alias /var/lib/mysql/ -&gt; /home/dev/Desktop/iiab/db/mysql/,
</code></pre>

<p>I am able to restart and reload apparmor successfully. </p>

<p>I'm using Ubuntu 16.04.</p>

<p>Anyone know what I am doing wrong?</p>