Reinstall MySQL (Community Server) on Mac OSX Snow Leopard (or How to downgrade to an older version of MySQL)
First, Read (or glance at this, especially if you are also using Rails/Ruby) upgrading-to-snow-leopard recommends using the 64 bit mysql
UPDATE:Do yourself a favor, if on Snow Leopard install the 64 bit (x86_64) MySQL server version! (The *.dmg) (then if you have to build the mysql ruby gem, do so with:
sudo env ARCHFLAGS="-arch x86_64" && sudo gem install -v=2.7 mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
Overview:
Recently, I upgraded from Leopard to Snow Leopard, for the most part it was quick and easy (about 1 hour, completely unattended)
Afterwards, I did however have to reinstall several apps, notably for me was MySQL.
I have 2 databases which I need for local development, which are fairly large and take a while to populate, so I wanted to maintain this data if possible. Unfortunely, since I did not dump the data before upgrading my OS and now, could not start the mysql server, there was no way to do the 'standard' mysql dump.
In my case, I was previously using a dev snapshot of the db, I wanted to install the same version to minimize issues. If it worked I can always do a proper data dump and upgrade to another version then.
Steps
Here is what I did which worked for me. (you will need to use the Terminal application for this, see 'Utilities')
In my case, I am using, mysql-5.4.3-beta-osx10.5-x86, your version may (probably will) be different, adjust the command to fit your version.
Back up past data
cd /usr/local
sudo tar -zcvf mysql-5.4.3-beta-osx10.5-x86.tar.gz mysql-5.4.3-beta-osx10.5-x86/
sudo mv mysql-5.4.3-beta-osx10.5-x86.tar.gz ~/Documents/
the first command places you in the correct directory
the second makes a tar archive (compressed) copy of the database files.
the third moves that into you home 'Documents' directory (for safe keeping)
(now your data should be safe and sound)
Now Uninstall Mysql: (be careful with these commands, you cant 'undo' them)
(taken from: uninstalling-mysql-on-mac-os-x-leopard pasted here for convenience)
To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:
• sudo rm /usr/local/mysql
• sudo rm -rf /usr/local/mysql*
• sudo rm -rf /Library/StartupItems/MySQLCOM
• sudo rm -rf /Library/PreferencePanes/My*
• edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
• rm -rf ~/Library/PreferencePanes/My*
• sudo rm -rf /Library/Receipts/mysql*
• sudo rm -rf /Library/Receipts/MySQL*
The last two lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version
• sudo rm -rf /var/db/receipts/com.mysql.*
(above needed to work for Snow Leopard)
Now Install Mysql:
Now go find a *.dmg of the same version, you were running. (you will probably have to grab it from an archive somewhere, I found mine here: http://archive.sunet.se/pub/databases/relational/mysql/Downloads/MySQL-5.4
Install both the mysql package and startup items package.
they should have installed with no issues.
try starting the server.
to start:
Library/StartupItems/MySQLCOM/MySQLCOM start
to stop:
Library/StartupItems/MySQLCOM/MySQLCOM stop
if that doesn't work (those are text files, you can 'less' them)
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
test a login
mysql -uroot (Enter)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.4.3-beta MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Great, that means it's working, Now, stop the database.
Load past data into New database
Get you old data into this instance.
cd ~/Documents/
sudo tar xzvf mysql-5.4.3-beta-osx10.5-x86.tar.gz
(this will uncompress your past data into this dir)
sudo mv mysql-5.4.3-beta-osx10.5-x86/data/YOURDB /usr/local/mysql-5.4.3-beta-osx10.5-x86/data/
sudo mv mysql-5.4.3-beta-osx10.5-x86/data/YOUR_OTHER_DB /usr/local/mysql-5.4.3-beta-osx10.5-x86/data/
All Done
now start your db, all should be well. (you will have to recreate any other mysql users you had)