如何将mysql数据库移动到另一个挂载点

时间:2022-09-24 11:13:27

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.

我有一个MySQL数据库,它变得越来越大,我想将整个数据库移动到另一个挂载点,我有足够的存储空间。我希望传输当前数据,并将新数据保存到新位置。

software stack: MySQL 5 running on FreeBSD 6

软件堆栈:在FreeBSD 6上运行的MySQL 5

3 个解决方案

#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. mv / var / lib / mysql /var/lib/mysql.backup

  4. mount your new partition under /var/lib/mysql
  5. 在/ var / lib / mysql下挂载新分区

  6. cp -r /var/lib/mysql.backup /var/lib/mysql
  7. cp -r /var/lib/mysql.backup / var / lib / mysql

  8. start mysqld

#2


  • Stop mysqld
  • Copy /var/lib/mysql (or whatever $datadir in my.cnf was set to) to the new location
  • 将/ var / lib / mysql(或my.cnf中的$ datadir设置为)复制到新位置

  • Either mount the new location under the old $datadir or modify the MySQL configuration in the file my.cnf to reflect the new location.
  • 在新的$ datadir下安装新位置或修改my.cnf文件中的MySQL配置以反映新位置。

  • Start mysqld

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

没有魔法涉及。 ;)但你应该确保,你使用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. 将文件rsync到新安装点

  4. either:
    1. change mysql.conf to tell MySQL where to find the files, or
    2. 改变mysql.conf告诉MySQL在哪里找到文件,或者

    3. make the current directory a symlnk to the new one
    4. 使当前目录成为新目录的symlnk

  5. 要么:改变mysql.conf告诉MySQL在哪里找到文件,要么将当前目录作为新目录的symlnk

  6. restart MySQL

#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. mv / var / lib / mysql /var/lib/mysql.backup

  4. mount your new partition under /var/lib/mysql
  5. 在/ var / lib / mysql下挂载新分区

  6. cp -r /var/lib/mysql.backup /var/lib/mysql
  7. cp -r /var/lib/mysql.backup / var / lib / mysql

  8. start mysqld

#2


  • Stop mysqld
  • Copy /var/lib/mysql (or whatever $datadir in my.cnf was set to) to the new location
  • 将/ var / lib / mysql(或my.cnf中的$ datadir设置为)复制到新位置

  • Either mount the new location under the old $datadir or modify the MySQL configuration in the file my.cnf to reflect the new location.
  • 在新的$ datadir下安装新位置或修改my.cnf文件中的MySQL配置以反映新位置。

  • Start mysqld

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

没有魔法涉及。 ;)但你应该确保,你使用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. 将文件rsync到新安装点

  4. either:
    1. change mysql.conf to tell MySQL where to find the files, or
    2. 改变mysql.conf告诉MySQL在哪里找到文件,或者

    3. make the current directory a symlnk to the new one
    4. 使当前目录成为新目录的symlnk

  5. 要么:改变mysql.conf告诉MySQL在哪里找到文件,要么将当前目录作为新目录的symlnk

  6. restart MySQL