Running MySQL (mysqld) as a user other than 'mysql' under Ubuntu 10.04 (Lucid Lynx)

On Monday afternoon, I upgraded my work machine's Linux install to Ubuntu 10.04 (Lucid Lynx). I've been working in Windows mostly for a the last few months, and keeping all my MySQL data in a TrueCrypt volume as sometimes I need to hold customer data, and we can't store it in plain text.

I decided to take that data with me to Linux, so mounted the Windows partition (actually, that was automatic), installed TrueCrypt, and mounted that volume. This does, however, mean that all the files and folders in that volume are owned by my user (drarok), and the permissions are set to 0700.

I didn't (and still don't) know if you could get TrueCrypt to mount volumes as another user, so decided to just run MySQL as my own user, changing the user and datadir settings in /etc/mysql/my.cnf. Being Ubuntu, I also had to edit /etc/apparmor.d/usr.sbin.mysqld, replacing the normal data directory with the TrueCrypt volume's data directory. Then I also edited /etc/init/mysql.conf, commenting out the "start on" lines, else MySQL would be trying to start up before TrueCrypt had mounted my volume.

I then proceeded to change ownership on /var/log/mysql, and /var/run/mysqld, then start MySQL with service mysql start. It worked! I now had MySQL running as my user, excellent!

I spent Tuesday working happily in Linux, shutting down at the end of the day as usual. When I came in on Wednesday, however, MySQL would not start! (Also, I couldn't contact the network via DHCP or manual address - but that's for another time).

After investigating, I found that /var/run/mysqld was owned by the 'mysql' user again! My mistake was not spotting the "Sanity Checks" in /etc/init/mysql.conf. I found the following line:

[ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld

… and replaced it with:

[ -d /var/run/mysqld ] || install -m 755 -o drarok -g root -d /var/run/mysqld

Not sure if this will help anyone else, but I'm almost certain it's one of those things that I'll wish I wrote down somewhere when it hits me again and I've forgotten the solutions.