Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
For me, Mysql did not restart after doing all steps
When I ran sudo systemctl status mysql I saw
Bad file descriptor error
I spent lots of time but then I found out it was AppArmor issue, I had to unlink AppArmor from Mysql
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/disable/usr.sbin.mysqld
this step is unnecessary and will cause the mysql startup to fail: sudo mkdir /var/lib/mysql/mysql -p
If you want AppArmor to play nice with the new volume, add two new rules to the /usr/sbin/mysqld block in the /etc/apparmor.d/usr.sbin.mysqld file. It should look like:
/usr/sbin/mysqld {
#...
# Allow data dir access
/mnt/volume_nyc1_01/mysql/ r,
/mnt/volume_nyc1_01/mysql/** rwk,
}
These rules are the exact read/write/lock permissions used for the previous data directory (/var/lib/mysql/) for MySQL.
After you have edited /etc/apparmor.d/usr.sbin.mysqld, restart the AppArmor service with:
sudo systemctl restart apparmor
And then restart the MySQL service with:
sudo systemctl restart mysql
As @SmallLightCyanDolphin stated, following the tutorial caused the mysql startup to fail.
And as @iamumairayub pointed out, it’s due to an AppArmor issue. But their solution is somewhat of the nuclear option, making AppArmor completely ignore any MySQL rules.
I wonder why the first time i used this process the database moving went according to plan (from /var/lib/mysql to /media/carlos/2u256_data/mysql) but then I installed a second hard drive (SSD) and the same process fails to start the MySQL database at the end of the process (moving from /media/carlos/2u256_data/mysql to /media/carlos/localSSD/mysql). I have followed also @iPwnPancakes instructions but I keep getting an exit-code when trying to start the database. Any ideas?
/dev/dm-0 960269336 446709448 464707204 50% /media/carlos/localSSD
/dev/dm-1 7750997556 802508912 6557772844 11% /media/carlos/2u256_data
I followed all the steps but mysql failed to start. That comment helped me in my case: dba.stackexchange.com/a/212331
mount --bind /newmysqldatadir /var/lib/mysql
In case if you are changing the datadir to somewhere under “/home”, you also need to do these steps https://stackoverflow.com/a/58912528 That is: Edit file /lib/systemd/system/mariadb.service
ProtectHome=true
to
ProtectHome=false
and do
systemctl daemon-reload
Struggled for days trying to make this work in ans aws ec2 ubuntu image home folder. put in a root subfolder and it worked.
I followed all the steps, but mysql does not start with the error:
job for mysql.service failed because the control process exited with error code. See … for Details.
I have created the original mysql path, but it doesn’t seem to help?
If I do the following, MySQL will not start.
mkdir /var/lib/mysql/mysql -p
I reinstalled MySQL and skipped the above direction in Step 4 of this tutorial and MySQL is working perfectly with my datadir on a separate drive. Maybe it’s permissions or something to do with AppArmor - but it obviously doesn’t need to exist in the releases I’m using.
I’m using a fresh install of Ubuntu 24.04, and MySQL 8.0.36 - both the latest releases as of this posting.
Writing for my future self so I don’t forget what to do.
stop mysql
sudo rsync -av /var/lib/mysql /mnt/MY_NEW_VOLUME
sudo mv /var/lib/mysql /var/lib/mysql.bak
cd /mnt/MY_NEW_VOLUME/
sudo chown -R mysql:mysql mysql
---
sudo mkdir -p /etc/apparmor.d/disable
sudo mv /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo systemctl restart apparmor
sudo nano /etc/fstab
add
/mnt/MY_NEW_VOLUME/mysql /var/lib/mysql none bind 0 0
sudo reboot