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:
当然其他答案都是有效的。但是,如果要保留默认配置,请执行以下操作:
- stop mysqld
mv /var/lib/mysql /var/lib/mysql.backup
- mount your new partition under
/var/lib/mysql
cp -r /var/lib/mysql.backup /var/lib/mysql
- start mysqld
mv / var / lib / mysql /var/lib/mysql.backup
在/ var / lib / mysql下挂载新分区
cp -r /var/lib/mysql.backup / var / lib / mysql
#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
将/ var / lib / mysql(或my.cnf中的$ datadir设置为)复制到新位置
在新的$ datadir下安装新位置或修改my.cnf文件中的MySQL配置以反映新位置。
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:
如果您可以容忍数据库因移动而停机:
- Shutdown MySQL
- rsync the files to the new mount point
- either:
- change
mysql.conf
to tell MySQL where to find the files, or - make the current directory a symlnk to the new one
改变mysql.conf告诉MySQL在哪里找到文件,或者
使当前目录成为新目录的symlnk
- change
- restart MySQL
将文件rsync到新安装点
要么:改变mysql.conf告诉MySQL在哪里找到文件,要么将当前目录作为新目录的symlnk
#1
Of course other answers are valid. But if you want to keep the default configuration, do following:
当然其他答案都是有效的。但是,如果要保留默认配置,请执行以下操作:
- stop mysqld
mv /var/lib/mysql /var/lib/mysql.backup
- mount your new partition under
/var/lib/mysql
cp -r /var/lib/mysql.backup /var/lib/mysql
- start mysqld
mv / var / lib / mysql /var/lib/mysql.backup
在/ var / lib / mysql下挂载新分区
cp -r /var/lib/mysql.backup / var / lib / mysql
#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
将/ var / lib / mysql(或my.cnf中的$ datadir设置为)复制到新位置
在新的$ datadir下安装新位置或修改my.cnf文件中的MySQL配置以反映新位置。
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:
如果您可以容忍数据库因移动而停机:
- Shutdown MySQL
- rsync the files to the new mount point
- either:
- change
mysql.conf
to tell MySQL where to find the files, or - make the current directory a symlnk to the new one
改变mysql.conf告诉MySQL在哪里找到文件,或者
使当前目录成为新目录的symlnk
- change
- restart MySQL
将文件rsync到新安装点
要么:改变mysql.conf告诉MySQL在哪里找到文件,要么将当前目录作为新目录的symlnk