Migrating MySql to larger disk on primary home system
Sunday, August 9, 2026 at 07:27:40
Stop mysql
sudo systemctl stop mysql sudo systemctl status mysql
Rsync to new location
sudo rsync -av /var/lib/mysql /mnt/new_disk/
mv original dir
sudo mv /var/lib/mysql /var/lib/mysql.bak
edit the mysql.cnf file
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
find datadir and change to new location
datadir = /mnt/new_disk/mysql
edit apparmor file (for ubuntu)
sudo nano /etc/apparmor.d/tunables/alias
change/add the following line
alias /var/lib/mysql/ -> /mnt/new_disk/mysql/,
restart everything
sudo systemctl restart apparmor sudo systemctl start mysql
Of course, I forgot that the mounted drive is ntfs so I could access from my dual boot windows side (rarely if ever used), so the owner of the files/directories can’t be changed. Sigh… putting everything back.
😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵😵
So, I ended up resizing the ntfs partition, making an ext4 partition in the leftover space, and moving mysql to that partition. Also, before doing all that, I rsync’d all the data to another system/drive.