Laravel — How to change MySQL data directory on Digital Ocean

Dilemmas:

Solutions:

# SSH as root user
$ ssh user@ip
# Create a mount point for your volume:
$ mkdir -p /mnt/database

# Mount your volume at the newly-created mount point:
$ mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_database /mnt/database

# Change fstab so the volume will be mounted after a reboot
$ echo '/dev/disk/by-id/scsi-0DO_Volume_database /mnt/database ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
mysqldump db_name --result-file=/mnt/database/backup/PRODUCTION-dump.sql --port=... --user=... -password
mysqldump db_name --result-file=/mnt/database/backup/PRODUCTION-dump.sql --port=... --single-transaction --quick --user=... -password
1 - Open SSH console:
- ssh user@ip
- sudo -i -> (user becomes root; sudo password needed)
2 - Put site into maintenance mode
- cd /home/user/site_name -> php artisan down
3 - Stop MySQL service (root)
- systemctl status mysql -> systemctl stop mysql -> systemctl status mysql
4 - Move database folder to new volume
- mv /var/lib/mysql /mnt/database/mysql
5 - Create a symbolic link (root)
- ln -s /mnt/database/mysql /var/lib/mysql -> ll /var/lib/ (make sure the link is there: the cyan color)
6 - Configure AppArmor Access
- nano /etc/apparmor.d/tunables/alias
- (insert this at the end of file) alias /var/lib/mysql/ -> /mnt/database/mysql/, (^O[save] -> ^X[exit])
- cat /etc/apparmor.d/tunables/alias (make sure new rule is there)
7 - Restart AppArmor
- systemctl restart apparmor
8 - Start MySQL Service
- systemctl start mysql -> systemctl status mysql
9 - Remove maintenance mode from site:
- php artisan up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store