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
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
- 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:
- 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
- change
- restart MySQL
来源:https://stackoverflow.com/questions/743245/how-to-move-a-mysql-database-to-another-mount-point