Tuesday, January 4, 2011

Completely Remove MySQL on Mac OS X

I was getting my Mac ready to do some Rails development with a MySQL database and I ran into a problem installing MySQL 5.5.8 on OS X 10.6.5.  I downloaded the .DMG and ran through the mysql-5.1.54-osx10.6-x86_64.pkg installer without a problem.  However, after installing the server and the MySQL.prefPane I could not start the server from the preference pane.  Then I noticed that the installer did not run scripts/mysql_install_db as part of the post installation process.  Well my first thought is that I obviously did something wrong so I thought I'd remove MySQL and start over again.  So, I did some googling and found these steps to completely remove MySQL:

  1. sudo rm /usr/local/mysql
  2. sudo rm -rf /usr/local/mysql*
  3. sudo rm -rf /Library/StartupItems/MySQLCOM
  4. sudo rm -rf /Library/PreferencePanes/My*
  5. (Edit /etc/hostconfig) sudo vi /etc/hostconfig (Remove line MYSQLCOM=-YES)
  6. sudo rm -rf /Library/Receipts/mysql*
  7. sudo rm -rf /Library/Receipts/MySQL*
  8. sudo rm -rf /var/db/receipts/com.mysql.*

Apparently the receipts are in a different location for the newer versions of MySQL so line #8 was added to clean them out as well.  Remember, these steps will completely remove MySQL and any data residing in the default locations.

So, back to my struggles.  I ended up installing MySQL 5.5.8 a couple of times using different archives with the same result so this removal process came in real handy...I almost made a script out of it.  After getting pretty frustrated with version 5.5.8 I ended up installing version 5.1.54 without a problem and it is running fine!?!?!



nbarthelemy said...

Thank you so much #8 was what every other post was missing.

Pete said...

I got the PreferencePane working by editing/usr/local/mysql/support-files/mysql.server with these values:


So now I could easily start & stop the server, but I could never get the mysql gem to work correctly. It would seem to install correctly, but running 'rake db:migrate' as a test would always return

uninitialized constant MysqlCompat::MysqlRes

I finally gave up & tried installing MySQL 5.1.54 but then ran into the problem that your step #8 fixed. Now MySQL runs fine and the gem installed correctly. So much wasted time....

Rod Biresch said...

I'm glad to hear that this post help you! I had problems installing the mysql gem. I finally got the gem installed using...

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config


Jérôme said...

Thanks Rod for the the step 8, hopefully Google found you! I could uninstall MySQL 5.1 with it.

Thanks Pete for the two lines, they fix well the preference panel and terminal command :)

Note: I didn't install the Automatic startup thing

Anonymous said...

this finally works - thanks, you're a great hero!

Mike said...

#8 was what was missing in all the other guides.

stammtisch said...

THNAK YOU for #8 !!!

Anonymous said...

Thanks a lot man!! really helpful and works like a charm

ankit goel said...

thanx a lot.. i installed mysql 5.5.28 8 times and couldnt get it to work..finally 5.1 is working great ..

Anonymous said...

Not so far I have found new cool tool to work with mySQL on mac os x - Valentina Studio. Its free edition can do things more than many commercial tools!!
I very recommend check it. http://www.valentina-db.com/en/valentina-studio-overview
You can install Valentina Studio (FREE) directly from Mac App Store: https://itunes.apple.com/us/app/valentina-studio/id604825918?ls=1&mt=12

newmac said...

sorry new to mac... Do i add the lines in terminal?

Rod Biresch said...

Yes, execute each command in the terminal

mahasiswa teladan said...

hi...Im student from Informatics engineering nice article,
thanks for sharing :)

Anonymous said...

I recommend using srm which overrites the data completely

alredi said...

I'm having problems with step #5. Once I delete the line, I have no idea how to progress. I tried CTRL-X, OPTION-X, CMD-X... (CTRL-X was recommended by another site). Any suggestions?

Rod Biresch said...

alredi, the command in step #5 puts you in the vi editor. To save your changes, press ESC then enter ':wq' without the single quotes. That will tell vi to 'w' write the changes and 'q' quit the editor. I suggest searching for 'vi commands' in your favorite web search tool.

Teemu Pasila said...

We have a problem installing mysql after this.

The install script I'm trying to run is: bash <(curl -Ls http://git.io/eUx7rg)

That I got from page:

It stops saying that the pid file in /var/local/mysql/data was not updated.

The computer is with Mac Os X Mavericks.

Anonymous said...

Teemu pasila did you try removing sequel pro too? I was having the same problem I restarted the computer after removing mysql and it worked fine.

David Blanchard said...

Fucking Genius. Appreciate the help.

Anonymous said...

Im getting the same problems with 5.1 unfortunately

shakthi vignesh said...

#5 doesnt wrks..
nothing in the hostconfig..
What i do..

Anonymous said...

This really helps! Completely remove all those broken versions and files and everything related to my*sql
Thanks for the help! Have to leave this comment

btw This allows anonymous comment which is just awesome..