Skip to content

Instantly share code, notes, and snippets.

@markalanevans
Last active August 23, 2018 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markalanevans/5474529 to your computer and use it in GitHub Desktop.
Save markalanevans/5474529 to your computer and use it in GitHub Desktop.
Moving Mysql to a different Partition on AWS. Using a symbolic link.
#On AWS:
#Create a new "Standard" volumn.
#Attach it do the Instance you want it on.
#- aws will likely give it /dev/sdf , most likely your linux distro will create /dev/xvdf (just replace s with xv)
#Now you can see your unpartition disk by running
fdisk -l
#You should see /dev/xvdf
#Partition it:
#Create the directory name for how you want to refer to it.
mkdir -m 000 /mysql_data
#Make sure that when the server reboots it automatically mounts this partition:
echo "/dev/xvdf /mysql_data auto noatime 0 0" | sudo tee -a /etc/fstab
#Mount it:
sudo mount /mysql_data
#Now lets move mysql over.
sudo service mysql stop
cd /var/lib
#Make a backup copy just incase ;)
sudo mv mysql mysql_bkp
#Copy it to the new location
sudo cp -Rp mysql /mysql_data/mysql #The p keeps the permissions when you copy it.
#Create a symbolic link to the new dir.
ln -s /mysql_data/mysql /var/lib/mysql
#Change the ownership of this dir back to mysql user.
chown -h mysql:mysql mysql
#If you have app armor installed, you will need to edit the /etc/apparmor.d/usr.sbin.mysqld file.
#Where ever there is a reference to /var/lib/mysql copy it and replace it with /mysql_data/mysql.
#Restart apparmor
/etc/init.d/apparmor restart
#Start MySQL
service mysql start
###References
#http://ubuntuatom.blogopogo.com/2011/04/16/list-all-mounted-or-unmounted-partitions-with-their-file-system-types/
#http://serverfault.com/questions/190685/whats-the-best-way-to-get-info-about-currently-unmounted-drives
#http://stackoverflow.com/questions/11535617/add-ebs-to-ubuntu-ec2-instance
#http://askubuntu.com/questions/118094/not-enough-disk-space-in-aws-instance
#http://serverfault.com/questions/249651/how-can-i-put-mysql-databases-in-different-disk-partitions-linux-ubuntu
#http://askubuntu.com/questions/137424/moving-mysql-datadir
#http://dev.mysql.com/doc/refman/5.1/en/symbolic-links-to-databases.html
@TheCloud
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment