how to move a mysql database to another mount point

雨燕双飞 提交于 2019-12-06 04:24:04

问题


I have a MySQL database, it is getting larger and larger and I want to move the whole database to another mount point, where I have enough storage. I want my current data to be transferred, and that new data get saved to the new position.

software stack: MySQL 5 running on FreeBSD 6


回答1:


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



回答2:


  • 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.




回答3:


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


来源:https://stackoverflow.com/questions/743245/how-to-move-a-mysql-database-to-another-mount-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!