1. Stop the database service
sudo service MySQL stop
2. Create a Data Migration destination folder (it should actually be mounted on a new hard disk)
Cd/var/lib
Ls-l
drwx------6 MySQL mysql 4096 January 9 09:26 mysql/#文件夹权限700, only MySQL users can access
sudo mkdir/mysqldata #创建目录
sudo chown-vr mysql:mysql/mysqldata/#更改所属组与用户, making it consistent with the original MySQL directory
#建议不使用rm移动目录, but use CP to avoid accidents
Su #切换到root账号, if you do not switch directly using root, you will be prompted to CP: Unable to get "/var/lib/mysql/*" File Status (STAT): There is no file or directory
cp-av/var/lib/mysql/*/mysqldata/
Exit # Cut back to the original account
sudo vim/etc/mysql/my.cnf #其中datadir为mysql路径, change to New path address
sudo vim/etc/apparmor.d/usr.sbin.mysqld #找到/var/lib/mysql commented out and changed to a new path
sudo service AppArmor Reload
sudo service MySQL restart
MySQL Database migration Ubuntu14.04