Changing your mysql data directory
The default specs for an EC2 instance include 165GB of local storage. That storage is split between 2 partitions. The default partition (/) is 9.85GB, with the rest in /mnt, which Amazon calls their “ephemeral storage”.
One problem that I ran into is the default location for installing applications, including mysql, is the default partition. So my mysql database was initially stored in what was left of the 9.85GB on the root drive. As the database grew, it quickly started to consume all of the storage on this partition.
I recommend you change your mysql data directory to the /mnt drive.
Here is how I did it.
Step 1. Backup your database!
Step 2. Shutdown mysql
service mysqld stop
Step 3. Create a new data directory on /mnt and change
Step 4. Change ownership of that directory to the same owner of your rails app
chown steveodom.www /mnt/mysql_db
Step 5. Modify the mysql config file
Which will look like this:
datadir=/mnt/mysql_db/ #was /var/lib/mysql/
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
Noticed I changed the very first line to point to /mnt/mysql_db.
Step 6. Move your databases to /mnt/mysql_db
mv mysql/your_database_name /mnt/mysql_db/
Step 7. Restart mysql
service mysqld start
Filed under: EC2, rails, Ruby on Rails, Uncategorized | 10 Comments