1. Stop the mysql service
service mysql stop
2. Migrate data files (assuming the migration target is /data/mysql)
cp -R /var/lib/mysql /data chown -R mysql:mysql /data/mysql
3. Modify the mysql configuration file (assuming the migration target is /data/mysql)
/etc/mysql/my.cnf
datadir = /data/mysql
/etc/inid.d/mysql Find the directory after the datadir section and change it to the following (assuming the migration target is /data/mysql)
datadir "/data/mysql"
4. Start the mysql service
service mysql start