I am using Raspbian Stretch:
lsb_release -a
This will output:
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch
Enter super user:
sudo su
Stop big processes:
systemctl stop nginx
systemctl stop {zabbix-server,zabbix-agent}
Exit root acount and backup existing database:
exit
sudo mysqldump zabbix | bzip2 -9 > dbdump.bz2
Move back to root:
sudo su
Stop MySQL and make sure it not running:
systemctl stop mysqld
List all storage device and show its ID's:
sudo blkid
This will report:
/dev/mmcblk0p1: LABEL="boot" UUID="5DB0-971B" TYPE="vfat" PARTUUID="89573528-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="060b57a8-62bd-4d48-a471-0d28466d1fbb" TYPE="ext4" PARTUUID="89573528-02"
/dev/sda1: UUID="b4bc781c-d3ed-4e71-9c9c-972cc43ca295" TYPE="ext4" PARTUUID="2f961579-01"
/dev/mmcblk0: PTUUID="89573528" PTTYPE="dos"
I will use PARTUUID as device identifier:
2f961579-01
Enter roots home:
cd
Make tmp dir:
mkdir /next
mount partition on this tmp dir with rewritable mode:
mount /dev/sda1 /next -o rw
Allow mysql user to be owner of next:
chown -R mysql:mysql /next
Check if mysql is stopped:
systemctl status mysqld
Enter MySQL user:
su -s /bin/bash mysql
Enter the dir where the stuff is placed:
cd /var/lib/mysql
Move everything to the /next and calculate how much time it took:
time mv * /next
List if there is any content in new location:
ls -l /next
exit mysql user:
exit
umount /next:
umount /next
Create backup of fstab:
cp /etc/{fstab,fstab.$(date +%Y%m%d%H%M)}
ls /etc/fstab*
Set new line:
echo "PARTUUID=2f961579-01 /var/lib/mysql ext4 defaults 0 1" >> /etc/fstab
Test if mounting works:
mount /var/lib/mysql
ls -l /var/lib/mysql
Test if umounting works:
umount /var/lib/mysql
Reboot the system to celebrate:
sudo reboot