My server was, and still is partially, running the v1 version of the documentation which means that MySQL, Apache and PHP where still the old versions provided by Server Logistics. The MySQL server was still running version 4.0.21 which is ancient and needed an upgrade. But it is a tricky task to perform. Upgrading software on my development server is easy and if it doesn’t work there is no big problem. Upgrading my live server is another thing. Besides my own sites I host some other sites for friends and although none of the sites can’t afford downtime it’s not something I was looking forward to.

So I needed to be prepared. I made a copy of my production servers harddisk to an external drive and used that image to boot my test mini. In this manner I had an exact copy of my live server on my internal network. In this manner I could play around without damaging anything.

The procedure I ended up with has caused a short downtime but you can’t do without as you need to shutdown the old server and start the new. It means several seconds of downtime which shouldn’t be much of a problem. I think nobody really noticed that my site was down for some seconds.

Here is how I did it:

  • Download the appropriate binary package for your Mac and the source code from MySQL.com
  • Use the binary installer and install MySQL 5.0.24a
  • Use my documentation to install the source code package. This is required to get the required shared libraries to compile other programs which need them.
  • Delete the MySQL startup item from /Library/StartupItems using the command sudo rm -rf /Library/StartupItems/MySQL
  • Delete the Server Logistics MySQL preference pane from /System/Library/PreferencePane using the command sudo rm -rf /System/Library/PreferencePane/MySQL.prefPane
  • Install the MySQL startup item from the binary installation package
  • Install the MySQL Preference pane from the binary installation package by double clicking on it.
  • Copy the fresh MySQL data directory for safekeeping using the command sudo mv /usr/local/mysql/data /usr/local/mysql/data.org
  • Copy the databases from the old server to the new by using the command: sudo cp -R /Library/MySQL/var /usr/local/mysql/data
  • Change the ownership of the data directory to set the correct permissions by using the command: sudo chown -R mysql /usr/local/mysql/data
  • Shutdown the old MySQL server, this can be done using the Preference Pane or issue the command mysqladmin shutdown -p followed by your MySQL password
  • Start the new server by issuing the command: sudo /usr/local/mysql/bin/mysqld_safe &. It should respond with: Starting mysqld daemon with databases from /usr/local/mysql/data
  • Next fix some issues with the MySQL passwords which have changed since version 4.1. You can do this by running the command: sudo /usr/local/mysql/bin/mysql_fix_privilege_tables --password=yourpassword
  • That’s it, you are running MySQL 5.0.24a. Congratulations.

Note: Depending on the speed at which information is inserted or updated in your database you can choose to bring down the old version of the database before copying it. This would mean that your site is down for a longer period but would guarantee that all the information is copied. I’ve chosen to copy the data first as my information isn’t updated that frequently.

Next I’m going to recompile all the mailserver components to use the new MySQL libraries. They all still work but you can better be safe than sorry. After that I’m going to upgrade Apache and PHP.