# - bof - # # :1 # - - # # - Move MySQL data_directory to Data - # https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04 # :1.1 # - - # # - Verify current location - # mysql -u root -p; select @@datadir; +-----------------+ | @@datadir | +-----------------+ | /var/lib/mysql/ | +-----------------+ 1 row in set (0.00 sec) exit; # :1.2 # - - # # - Stop database - # sudo systemctl status mysql; sudo systemctl stop mysql; sudo systemctl status mysql; ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: inactive (dead) since Tue 2018-08-07 19:40:51 EDT; 13s ago Process: 9451 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS) Process: 9428 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 9453 (code=exited, status=0/SUCCESS) Aug 06 22:44:54 uServerHome systemd[1]: Starting MySQL Community Server... Aug 06 22:44:54 uServerHome systemd[1]: Started MySQL Community Server. Aug 07 19:40:49 uServerHome systemd[1]: Stopping MySQL Community Server... Aug 07 19:40:51 uServerHome systemd[1]: Stopped MySQL Community Server. # :1.3 # - - # # - Copy files - # sudo rsync -av /var/lib/mysql /Data; sudo rsync -av /var/lib/mysql /Data/Databases; # :1.4 # - - # # - Backup data directory - # sudo mv /var/lib/mysql /var/lib/mysql.bak; # :2 # - - # # - Configuration - # # :2.1 # - - # # - Edit mysql.cnf - # sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf; Find datadir= ... datadir = /Data/mysql datadir = /Data/Databases/mysql # :3 # - - # # - Configuring AppArmor access control rules & Restart AppArmor - # # :3.1 # - - # # - Modify alias file - # sudo vim /etc/apparmor.d/tunables/alias; Add: ... alias /var/lib/mysql/ -> /Data/mysql/, alias /var/lib/mysql/ -> /Data/Databases/mysql/, # :3.2 # - - # # - Restart AppArmor - # sudo systemctl restart apparmor; # :4 # - - # # - Restarting MySQL, Create the minimal directory - # # :4.1 # - - # # - Restart MySQL - # /usr/share/mysql/mysql-systemd-start # :4.2 # - - # # - Create the minimal directory - # sudo mkdir /var/lib/mysql/mysql -p; # :4.3 # - - # # - Restart MySQL - # sudo systemctl start mysql; sudo systemctl status mysql; # :5 # - - # # - Verify new location, Remove backup data directory & Restart MySQL - # # :5.1 # - - # # - Verify new location - # mysql -u root -p; select @@datadir; +--------------------+ | @@datadir | +--------------------+ | /home/Data1/mysql/ | +--------------------+ 1 row in set (0.00 sec) exit # :5.2 # - - # # - Remove backup data directory - # sudo rm -Rf /var/lib/mysql.bak; # :5.3 # - - # # - Restart MySQL - # sudo systemctl restart mysql; sudo systemctl status mysql; # - eof - #