If you’re following the instructions on the Ruby on Rails blog for upgrading to Snow Leopard, you should notice that one of the recommended steps is installing the 64-bit version of MySQL. What the article fails to mention is that there are a couple of clean-up steps that you should do, and that you will also need to restore your old data directory or risk losing your development databases.
The tips below assume that you’ve already downloaded and installed MySQL for OS X 10.5, 64-bit.
1. Shut down MySQL
If you installed MySQL using MacPorts, type this in Terminal to stop the MySQL daemon:
sudo /opt/local/share/mysql5/mysql/mysql.server stop
Otherwise, if you used the installer from mysql.com, go to Apple Menu > System Preferences and click on the MySQL preference pane. You’ll get a message stating that System Preferences has to restart; this is because the preference pane is a 32-bit app, and System Preferences is now a 64-bit app.
You’re going to get tired of restarting System Preferences, so I recommend that you go download the replacement pref pane from swoon dot net. Go ahead, I’ll wait.
When you’re all set, make sure that MySQL is not running. For a sanity check, fire up Applications > Utilities > Activity Monitor and search for ’sql’:
If you shut down MySQL correctly, you should not see the mysqld process running.
2. Locate your old data directory
Terminal is your friend:
Cerberus:~ bantik$ cd /usr/local
Cerberus:local bantik$ ls -al
total 7
drwxr-xr-x 16 root wheel 544 Sep 2 21:38 .
drwxr-xr-x@ 12 root wheel 408 Sep 2 21:20 ..
drwxr-xr-x 3 root wheel 102 Sep 2 20:52 OpenSourceLicenses
drwxr-xr-x 3 root wheel 102 Sep 2 20:52 OpenSourceVersions
drwxr-xr-x 36 root wheel 1224 Sep 2 20:52 bin
drwxr-xr-x 4 root wheel 136 Sep 2 20:52 etc
drwxr-xr-x 9 root wheel 306 Sep 2 20:52 git
drwxr-xr-x 5 root wheel 170 Sep 2 20:52 include
drwxr-xr-x 42 root wheel 1428 Sep 2 20:52 lib
drwxr-xr-x 3 root wheel 102 Sep 2 20:52 man
lrwxr-xr-x 1 root wheel 27 Sep 2 21:38 mysql -> mysql-5.1.37-osx10.5-x86_64
drwxr-xr-x 3 root wheel 102 Sep 2 21:38 mysql-5.0.77-osx10.5-x86
drwxr-xr-x 18 root wheel 612 Sep 2 22:03 mysql-5.1.37-osx10.5-x86_64
drwxr-xr-x 4 root wheel 136 Sep 2 20:52 share
drwxr-xr-x 4 root wheel 136 Sep 2 20:52 src
Cerberus:local bantik$
The new version of MySQL is aliased to /usr/local/mysql, and the old version is still there: in this case, in mysql-5.0.77-osx10.5-x86 (your version number may vary, but just look for the folder with the largest version number that ends with x86). Your data directory with all of your development databases is safely tucked away inside.
3. Copy your old data folder into the new MySQL directory
cd into the folder you located in the step above and then do the following:
sudo cp -R data ../mysql/data_prev
Now cd to the directory where the new version lives, move the (empty) data directory aside, and replace it with your previous version:
cd ../mysql
sudo mv data data_aside
sudo mv data_prev data
You’ll also need to change the owner on the newly moved data directory:
sudo chown -R _mysql:wheel data
4. Restart MySQL
Go back to Apple Menu > System Preferences > MySQL and click the ‘Start MySQL Server’ button. If you see a message like this:
Warning: The /usr/local/mysql/data directory is not owned by the ‘mysql’ or ‘_mysql’ user.’
…then you didn’t correctly change the owner in the previous step.
5. Delete your old MySQL installation(s)
Once you are sure that you’ve recovered your old data (hint: try script/console inside one of your Rails apps and see if your database exists), you can safely remove the old MySQL installation:
sudo rm -rf mysql-5.0.*
That’s it!
Everything should now be right with the world. Go write some code and enjoy the new 64-bit goodness of Ruby, Rails, and MySQL on Snow Leopard.
No Comments »