- Check the current data directory. By default, the data directory is /var/lib/mysql:
mysql> show variables like '%datadir%';+---------------+-----------------+| Variable_name | Value |+---------------+-----------------+| datadir | /var/lib/mysql/ |+---------------+-----------------+1 row in set (0.04 sec)
- Stop mysql and make sure it has stopped successfully:
shell> sudo systemctl stop mysql
- Check the status:
shell> sudo systemctl status mysql
It should show Stopped MySQL Community Server.
- Create the directory at the new location and change the ownership to mysql:
shell> sudo mkdir -pv /datashell> sudo chown -R mysql:mysql /data/
- Move the files to the new data directory:
shell> sudo rsync -av /var/lib/mysql /data