Skip to content

Instantly share code, notes, and snippets.

@rhemz
Created February 27, 2017 18:46
Show Gist options
  • Save rhemz/b3ecaf09b3152c6fd929ff65c2e2c3c2 to your computer and use it in GitHub Desktop.
Save rhemz/b3ecaf09b3152c6fd929ff65c2e2c3c2 to your computer and use it in GitHub Desktop.
add ec2 block device
sudo mkdir /data
sudo mkfs.ext4 /dev/xvdf
# then
sudo mount -t ext4 /dev/xvdf /data/
# or add to /etc/fstab
/dev/xvdf /data ext4 defaults,nofail 0 2
sudo mount -a
@rhemz
Copy link
Author

rhemz commented Feb 27, 2017

To move MySQL data and binlog storage to the new volume, continue with these steps:

Make mysql user the owner of /data:
sudo mkdir -p /data/mysql/binlogs
sudo chown -R mysql:mysql /data/mysql

Stop MySQL:
sudo /etc/init.d/mysql stop

Copy the existing data folder (located in /var/lib/mysql by default) into /data:
sudo cp -p -R /var/lib/mysql /data/
sudo cp -p -R /var/log/mysql/mysql-bin.* /data/mysql/binlogs/

Edit the MySQL configuration file and:

  1. change the value of datadir (which should be /var/lib/mysql) to the new data folder (/data/mysql).
  2. change the value of log_bin (which should be /var/log/mysql/mysql-bin.log) to the same file in the new log folder (/data/mysql/binlogs/mysql-bin.log)
    sudo nano /etc/mysql/my.cnf

Reset AppArmor (Ubuntu Server only?):
sudo nano /etc/apparmor.d/usr.sbin.mysqld
Look for lines beginning with /var/lib/mysql or /var/log/mysql. Change them to their appropriate new locations (/data/mysql and /data/mysql/binlogs, respectively) and save the file.

Restart AppArmor profiles:
sudo service apparmor reload

Restart MySQL:
sudo service mysql start

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