Skip navigation.

MySQL: changing data dir

I wanted to change the location of the datadir for mysql. I had some troubles accomplishing this and the solutions I saw online were not fully accurate, so for the record, here is how I achieved this.

I installed Kubuntu 9.10 in my new computer, and wanted to move my old database data from my old computer. Also, I wanted to change the datadir to /home/mysql/ instead of the default /var/lib/mysql/.

Stop the mysqld server:

/etc/init.d/mysql stop

edit my.cnf:

vi /etc/mysql/my.cnf
// set:
// dir   = /home/mysql

I don't know what apparmor is for, but there was a note in the above my.cnf file to update it as well, so I also replaced /var/lib/mysql/ with /home/mysql/ there:

vi /etc/apparmor.d/usr.sbin.mysqld
// set:
//   /home/mysql/ r,
//   /home/mysql/** rwk,

Restart apparmor, which is a crucial step that I missed earlier:


/etc/init.d/apparmor restart

restart mysql:

/etc/init.d/mysql start

Final step:

rejoice

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • Allowed HTML tags: <a> <em> <strong> <blockquote> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.