分享

Linux Ubuntu move mysql database to other path in 5 minutes

 simplelam 2014-04-29
  • Open the terminal
  • Stop MySQL with the command
    /etc/init.d/mysql stop
  • Move existing data directory (which is located in /var/lib/mysql) to new dir /usr/new_datadir using the command
    mv /var/lib/mysql /usr/new_datadir
  • Create symlink from new dir to old one
    ln -s /usr/new_datadir /var/lib/mysql
  • Don't chnage /etc/mysql/my.cnf =)))
  • Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.
  • In the terminal, enter the command
    vim /etc/apparmor.d/usr.sbin.mysqld
  • Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadir In my case it was:
    .........
    /var/lib/mysql/ r,
    /var/lib/mysql/** rwk,
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    #
    /usr/new_datadir r,
    /usr/new_datadir** rwk,
    /usr/new_datadir r,
    /usr/new_datadir* rw,
    ........
  • Restart the AppArmor profiles with the command
    /etc/init.d/apparmor restart
  • Restart MySQL with the command
    /etc/init.d/mysql restart
  • MySQL should now start without any errors, have fun! See also article How to move the mysql datadir, Ubuntu change datadir issue
    • 本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
      转藏 分享 献花(0

      0条评论

      发表

      请遵守用户 评论公约

      类似文章 更多