Last active
October 8, 2021 03:29
-
-
Save pacmac/cb60e8e74ce459a35bc3fb13b7a4d42e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Move default mysql databases to new volume. | |
############################################## | |
# https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04 | |
echo "This cannot be executed" | |
exit 1; | |
## Backup before we start just in case. | |
/usr/share/scripts/cron/mybackup.sh | |
## Get the datadir from mysql | |
mysql -u root -p -e "select @@datadir;" | |
## Stop MYSQL | |
############# | |
systemctl stop mysql; | |
systemctl status mysql; | |
## Make File System | |
################### | |
mkfs.ext4 "/dev/disk/by-id/scsi-0Linode_Volume_mysql" | |
## Mount new Volume | |
################### | |
mkdir "/mnt/mysql" | |
mount "/dev/disk/by-id/scsi-0Linode_Volume_mysql" "/mnt/mysql" | |
## cleanup | |
rm -rf /mnt/mysql/lost+found | |
## add to fstab | |
############### | |
nano /etc/fstab | |
/dev/disk/by-id/scsi-0Linode_Volume_mysql /mnt/mysql ext4 defaults,noatime,nofail 0 2 | |
## sync files & folders | |
####################### | |
rsync --progress -av /var/lib/mysql /mnt; | |
mv /var/lib/mysql /var/lib/mysql.bak; | |
## mysql-systemd-start checks for the existence of either a directory, -d, or a symbolic link, -L | |
################################################################################################# | |
mkdir /var/lib/mysql/mysql -p | |
## change datadir in my.cnf | |
########################### | |
nano nano /etc/mysql/my.cnf | |
# datadir=/mnt/mysql | |
cat /etc/mysql/my.cnf | grep datadir | |
## Configuring AppArmor Access Control Rules | |
############################################# | |
nano /etc/apparmor.d/tunables/alias | |
## PAC 211008 | |
alias /var/lib/mysql/ -> /mnt/mysql/, | |
systemctl restart apparmor | |
systemctl status apparmor | |
## Restart & check all is OK | |
############################ | |
systemctl start mysql; | |
systemctl status mysql; | |
## Confirm datadir | |
################## | |
mysql -u root -p -e "select @@datadir;" | |
## Restart again just to be sure. | |
systemctl restart mysql; | |
systemctl status mysql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment