how to move a mysql database to another mount point

爷,独闯天下 提交于 2019-12-04 09:49:20

Of course other answers are valid. But if you want to keep the default configuration, do following:

  1. stop mysqld
  2. mv /var/lib/mysql /var/lib/mysql.backup
  3. mount your new partition under /var/lib/mysql
  4. cp -r /var/lib/mysql.backup /var/lib/mysql
  5. start mysqld
  • Stop mysqld
  • Copy /var/lib/mysql (or whatever $datadir in my.cnf was set to) to the new location
  • Either mount the new location under the old $datadir or modify the MySQL configuration in the file my.cnf to reflect the new location.
  • Start mysqld

There's no magic involved. ;) But you should make sure, that you copy all permissions with the files of MySQL.

If you can tolerate the database being down for the move:

  1. Shutdown MySQL
  2. rsync the files to the new mount point
  3. either:
    1. change mysql.conf to tell MySQL where to find the files, or
    2. make the current directory a symlnk to the new one
  4. restart MySQL
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!