O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. 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)
  1. Stop mysql and make sure it has stopped successfully:
shell> sudo systemctl stop mysql
  1. Check the status:
shell> sudo systemctl status mysql

It should show Stopped MySQL Community Server.

  1. Create the directory at the new location and change the ownership to mysql:
shell> sudo mkdir -pv /datashell> sudo chown -R mysql:mysql /data/
  1. Move the files to the new data directory:
shell> sudo rsync -av /var/lib/mysql /data

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required