1. Stop MySQL First
/etc/init.d/mysql stop
2. Create a directory as a directory to temporarily store MySQL data
Mkdir/mysqldata
MySQL data in 3.ubuntu is stored in the/var/lib/mysql directory, and belongs to the MySQL user and MySQL group, the permissions are 700, so we also need to give the migrated directory/mysqldata the same users and groups and permissions
CHOWN-VR Mysql:mysql/mysqldata
chmod 700/mysqldata
4. Copy the contents of the MySQL file to the Mysqldata file, must be root user or not have permission
cp-av/var/lib/mysql/*/mysqldata
5. Modify the MySQL configuration file, ubuntu MySQL configuration file placed in/etc/mysql/my.cnf, modify the My.cnf file as follows:
Comment out the previous DataDir directory add a new DataDir directory
6. Also need to modify a file,/etc/apparmor.d/usr.sbin.mysqld, comment/var/lib/mysql/r, and/var/lib/mysql/** rwk, add the following two lines
/MYSQLDATA/R,
/mysqldata/** Rwk,
7 After the modification is complete, restart AppArmor and MySQL.
Service AppArmor Reload
/etc/init.d/mysql start
8. Test Data Migration success
Login database: Mysql-u root-p
Create Database etst; Create a database
This database exists to indicate successful migration
9. Finally, you can safely delete the files under the previous/var/lib/mysql/
Rm-r/var/lib/mysql/*
Migration of data in Ubuntu