title: MySql/MariaDB cannot change default datadir on Debian 9.1 server
body: <p>I have a problem to move the default datadir of Maria DB to another partition, it appears to be very common but i tried everything I can without luck.</p>
  
  <p>Mysql is installed as Mariadb 10.1.26 with the default debian package (<code>apt-get install mysql-server</code>) on a Debian 9.1 (stretch) server, <code>mysqld -v</code> returns <code>mysqld 10.1.26-MariaDB-0+deb9u1</code></p>
  
  <p>Default_mysql_datadir : <code>/var/lib/mysql</code></p>
  
  <p>New_mysql_datadir : <code>/home/mysql</code></p>
  
  <p><code>/var/lib/mysql</code> is mounted to "<code>/</code>" (<code>/dev/md3</code>) </p>
  
  <p><code>/home/mysql</code> is mounted to "<code>/home</code>" (<code>/dev/md4</code>)</p>
  
  <p>What I've tried</p>
  
  <pre><code># systemctl stop mysql
  # mv /var/lib/mysql /home
  </code></pre>
  
  <p>Change datadir in /etc/mysql/my.cnf</p>
  
  <pre><code># datadir = /home/mysql
  </code></pre>
  
  <p>Check if the rights/permissions are ok</p>
  
  <p><code># chown -R mysql.mysql /home/mysql</code></p>
  
  <p><strong>apparmor is NOT installed</strong> nor running on the system though the <code>/etc/apparmor.d/usr.sbin.mysqld</code> file is existing with the following rules :</p>
  
  <pre><code>/home/mysql/ r,
  /home/mysql/** rwk,
  </code></pre>
  
  <p>I even tried to create and empty <code>/var/lib/mysq</code> folder refering to this <a href="https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1574782" rel="nofollow noreferrer">bug</a></p>
  
  <p>But when I start I always get the same error :</p>
  
  <pre><code># systemctl start mysql
  [Warning] Can't create test file /home/mysql/&lt;user&gt;.lower-test
  #007/usr/sbin/mysqld: Can't change dir to '/home/mysql/' (Errcode: 13 "Permission denied") 2017-09-07  0:16:59 140119808397888 [ERROR] Aborting
  mariadb.service: Main process exited, code=exited, status=1/FAILURE
  Failed to start MariaDB database server.
  mariadb.service: Unit entered failed state.
  mariadb.service: Failed with result 'exit-code'.
  </code></pre>
  
  <p>Any suggestion ?</p>
  
  <p>Thanks</p>