By default the mysql install the datadir at /var/lib/mysql. Unfortunately, people usually did partition their hard disk, or buy a new hard drive later. In such a case, you would like to move the *huge* datadir to another disk to both boost the speed by parallel in I/O and utilize space smartly. Here's what you should do:
- Stop your mysql service.
sudo /etc/init.d/mysql stop
- Copying all files from old location to new location and preserver the ownership and timestamp information.
sudo cp -r -p /var/lib/mysql /newlocation/
- Update your mysql configuration file:
sudo vim /etc/mysql/my.cnf
datadir = /newlocation/mysql #old: /var/lib/mysql
- Update the second configuration file for apparmor:
/newlocation/mysql/ r, #/var/lib/mysql/ r,
/newlocation/mysql/** rwk, #/var/lib/mysql/** rwk, - (Optional) Rename the old folder to prevent confusing.
sudo mv /var/lib/mysql /var/lib/mysql.bak
- Restart your apparmor & mysql service.
sudo /etc/init.d/apparmor reload
sudo /etc/init.d/mysql start
- Delete the old location
sudo rm -rf /var/lib/mysql.bak
No comments:
Post a Comment