Changing MySQL data directory

Instructions for next time I forget:

  1. First create the new dir:
    # mkdir /data/mysql
  2. Move the old mysql data to the new dir:
    # cp /usr/lib/mysql/* /data/mysql/
  3. Set the right owner:
    # chown mysql: /data/mysql -R
  4. Edit mysql config file with new location of “datadir”
    # vi /etc/mysql/my.cnf
  5. Change mysql’s home dir in /etc/passwd
  6. If you are running apparmor you will get errors like these:

    InnoDB: Operating system error number 13 in a file operation.

    Can’t create test file

    or mysql will take ages to load and not start at all.
    Look for this file: /etc/apparmor.d/usr.sbin.mysqld and add these entires to the correct spot:

    /data/mysql/ r,
    /data/mysql/** rwk,

    then restart apparmor /etc/init.d/apparmor restart

Leave a Reply

Your email address will not be published.