Mysql – Remove MySQL (from Apple) on OS X Server Lion

mac-osxmac-osx-serverMySQLosx-lion

I have a Lion Server (upgraded from a Snow Leopard Server), which still has the Apple provided MySQL 5.0 server [mysql Ver 14.12 Distrib 5.0.92, for apple-darwin10.0 (i386)]. Without out rebuilding the entire box, I'm trying to determine how to remove all traces of the legacy Apple distributed MySQL server.

The current MySQL server has no data that needs to be retained.

I've searched for the answer, but it seems most responses assume you are either running a Homebrew or MySQL.com build. The Apple bundled version seems to not use the standard paths or file names.

Once it is removed, I'd like to do a clean install of a more current version of MySQL.

A quick run of find to locate some traces of MySQL shows the following results:

find / -name mysql -print 2> /dev/null
/Previous System/private/etc/raddb/sql/mysql
/private/etc/raddb/sql/mysql
/private/var/mysql
/private/var/mysql/mysql
/usr/bin/mysql
/usr/share/mysql

I see nothing MySQL related in /Library/Receipts or /Library/Receipts/db.

# ls -la /Library/Receipts/
total 24
drwxrwxr-x   6 root        admin   204 Jul 24  2011 .
drwxr-xr-x+ 67 root        wheel  2278 Mar  8 07:43 ..
-rw-r--r--@  1 root        admin     0 Jul 24  2011 .SetupRegComplete
-rw-r--r--   1 root        admin     0 Jul 24  2011 BSD.pkg
-rw-r--r--   1 root        admin  9594 Mar 24 15:29 InstallHistory.plist
drwxr-xr-x   2 _installer  admin    68 Jun 22  2011 db

I'm not even seeing anything in /Library/StartupItems.

Running 'ps -A' gives a few more clues.

79 ??         0:20.51 /usr/libexec/mysqld --socket=/var/mysql/mysql.sock --user=mysql --port=3306 --datadir=/var/mysql --pid-file=/var/mysql/coresrv01.mydomain.com.pid

If anyone can share some pointers, I would be extremely grateful.

Best Answer

I figured it out with some trial and error. Run the following script (with sudo) and it will remove all traces of the Apple provided MySQL server.

WARNING -- This will DELETE ALL DATABASES that existed on the Apple bundled MySQL 5.0 Server. Make absolutely certain you have made any needed backups. You have been warned!

#!/bin/bash

# Stop MySQL daemon
launchctl unload /System/Library/LaunchDaemons/org.mysql.mysqld.plist

# Remove Configuration Info
rm -fr /System/Library/LaunchDaemons/org.mysql.mysqld.plist
rm -fr /etc/my.cnf

# Remove old data stores / lock files / socket
rm -fr /private/var/mysql

# Remove binaries and libraries
rm -fr /usr/bin/mysql*
rm -fr /usr/libexec/mysql*

# Remove documentation / man pages
rm -fr /usr/share/info/mysql.info
rm -fr /usr/share/man/man1/mysql*
rm -fr /usr/share/man/man5/mysql*
rm -fr /usr/share/man/man8/mysql*
rm -fr /usr/share/mysql

Once the script has been run, installing MySQL 5.5 64-bit pkg will work without any problem.