Categories
Configuration

Configuring MySQL to Run in EC2's EBS under a Fedora AMI

There’s a lot of buzz around Amazon’s recent announcement/availability of their EBS add-on for EC2. The main reason being that it gets around the deficiency of EC2 wherein you lose all your locally-stored data if someone or something crashes your EC2 instance.

Certainly, one of the main uses of EBS will be to persistently host a database server. There have been some tutorials as to how to set up MySQL to use an EBS share. One that I especially appreciated was Eric Hammond’s tutorial. Unfortunately, it didn’t work out-of-the-box for me when running a Fedora 8-based AMI rather than an Ubuntu-based AMI the tutorial uses.

Since I had to tweak a few things to get it to work, I thought I’d share the solution in case you run into the same problem. It’s also good to document it for when my memory fails me 😉

The following is an addendum to the above mentioned tutorial that I used to get MySQL working on an EBS share using Fedora 8. For brevity I refer you to the tutorial for all steps apart from the section titled “Configuring MySQL to use the EBS volume”. Specifically, I used the AMI “ami-2b5fba42” image that is a Fedora 8 image that doesn’t include MySQL. I installed MySQL (5.x) on the system using yum.

In actuality, this probably applies more broadly than EC2 and rather describes some tweaks one would need to make to get MySQL running from a non-standard location on Fedora.

  1. First, stop the MySQL instance if it’s running: # /etc/init.d/mysql stop
  2. Next, create the paths for MySQL: # mkdir -p /vol/lib /vol/log
  3. Then mv /var/lib/mysql /vol/lib/ && mv /var/log/mysql /vol/log/
  4. Open your MySQL configuration file (mine was at /etc/my.cnf) and replace all instances of "/var/" with "/vol/" as /vol is used as the new MySQL home in the rest of the tutorial. (/vol is mounted against the EBS-backed device.)
  5. Open your MySQL startup script (mine was at /etc/init.d/mysqld) and replace all instances of "/var/" with "/vol/" as per the rest of the tutorial
  6. In the MySQL startup script, find the line that calls # /usr/bin/mysqladmin and add the 'socket file' command line option to point to our non-standard socket file ($socketfile): /usr/bin/mysqladmin -S$socketfile
  7. Next, start the MySQL instance running: # /etc/init.d/mysql start

Note that from this point you have to call most--if not all--MySQL command line utilities with the socket file argument. This file is specified in your MySQL configuration. If you forget, the command line will give you an error that should remind you. For example...

# mysql -uroot

...yields...

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The biggest change needed was to update the references in /etc/init.d/mysqld to point to /vol and add the explicit socket file argument.