title: Change Mysql Data Directory in Debian 7?
body: <p>I have a separate partition that holds both my www and mysql folders. </p>
  
  <p>I have that partition set to automount at boot, and the apache2 starts fine, no errors.</p>
  
  <p>However, when I just recently removed all traces of mysql-server-5.5, rebooted then restarted it, it would work normally.</p>
  
  <p>But the second I make changes to my.cnf to point to /media/server/mysql, and try to start mysql then it error's out.</p>
  
  <p>Here is the list of steps I have followed so far. Be advised, that Debian does not have apparmor, as far as I know, so I skipped that step.</p>
  
  <pre><code>Stop MySQL using the following command:
  
  sudo /etc/init.d/mysql stop
  
  Copy the existing data directory (default located in /var/lib/mysql) using the following command:
  
  sudo cp -R -p /var/lib/mysql /newpath
  
  edit the MySQL configuration file with the following command:
  
  gedit /etc/mysql/my.cnf
  
  Look for the entry for datadir, and change the path (which should be /var/lib/mysql) to the new data directory.
  
  In the terminal, enter the command:
  
  sudo gedit /etc/apparmor.d/usr.sbin.mysqld
  
  Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path.
  Save and close the file.
  
  Restart the AppArmor profiles with the command:
  
  sudo /etc/init.d/apparmor reload
  
  Restart MySQL with the command:
  
  sudo /etc/init.d/mysql restart
  
  Now login to MySQL, and you can access the same databases you had before.
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/1795176/how-to-change-mysql-data-directory">How to change MySQL data directory?</a></p>
  
  <p>Although I also looked at the link here <a href="https://askubuntu.com/questions/137424/moving-mysql-datadir">https://askubuntu.com/questions/137424/moving-mysql-datadir</a></p>
  
  <p>My guess is that this is a permissions issue, but I could be wrong.</p>
  
  <pre><code>root@debian:~# chown -R mysql:mysql /media/server/mysql
  root@debian:~# sudo /etc/init.d/mysql restart
  [ ok ] Stopping MySQL database server: mysqld.
  [FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
  </code></pre>
  
  <p>I'll admit I am still a newb at linux, so I may be doing things, that other's recommend, without really understanding what it is really doing.</p>
  
  <p>It gives no details about why it is failing.</p>
  
  <p>One other option, I may consider doing, is re-enable it to use the default data dir, and then just copy mysql files back from the partition.</p>
  
  <p>But that denies the whole point of having a dedicated partition for webdev.</p>
  
  <p>I appreciate any comments or efforts, thank you.</p>