Last Updated: January 20, 2018
· corysimmons
Cory simmons 700

Uninstall all those broken versions of MySQL and re-install it with Brew on Mac Mavericks

Remove MySQL completely per The Tech Lab

  • ps -ax | grep mysql
  • stop and kill any MySQL processes
  • brew remove mysql
  • brew cleanup
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/var/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • 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*
  • sudo rm -rf /private/var/db/receipts/*mysql*
  • restart your computer just to ensure any MySQL processes are killed
  • try to run mysql, it shouldn't work

Brew install MySQL per user Sedorner from this StackOverflow answer

  • brew doctor and fix any errors
  • brew update
  • brew install mysql
  • unset TMPDIR
  • mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
  • mysql.server start
  • run the commands Brew suggests, add MySQL to launchctl so it automatically launches at startup

mysql should now work and be running all the time as expected


Say Thanks

44 Responses
Add your response


On the 'mysqlinstalldb' command, there needs to be a space between the 'whoami' and the '--basedir' - for me it was a cut&paste gotcha. Otherwise, this was a great help in removing a munged installation, because the filesystem locations seem to be different for each Mac OS and this is the only one I found for Mavericks that pointed me to /usr/local/var/mysql, where all the 'bad' stuff was hiding.

over 1 year ago ·
Cory simmons 700

Oops, it was there but because of the backticks in the command markdown was breaking.

over 1 year ago ·
93615cd1f7592e7bb2be746cefa091bf normal

You sir, are a gentleman and a scholar. You have now enabled me to actually start working again :D

over 1 year ago ·
Zfxylvzb normal

Thank you for this. Between the teams I work with and people wanting to get into the backend of my laptop, my files were all weirded out. This set everything straight, and I was able to get MySql running again!

over 1 year ago ·

<3 !

over 1 year ago ·
F8539dcb1d060b5bcb2ca53e8b1ce59a normal

Lordy lordy lordy. Thank you for this. I was struggling quite a bit with a MySQL install. I still don't know exactly what I was doing wrong, but this worked. THANK YOU!

over 1 year ago ·

This all worked great, thanks for helping me get mysql back up and running.

btw if anyone gets this error:
[ERROR] /usr/local/opt/mysql/bin/mysqld: unknown variable '--generallogfile=/var/log/mysqldquery.log'

Go to /etc/my.cnf and delete the line, then try mysql.server start again.

over 1 year ago ·

Even for a noob like me, it took just a few google searches to clean several failed/broken/mysterious installs and get a clean one going. Thanks a lot for taking the time to compile.

I don't know if my path through this was typical, but you may want to bring about that the stop/kill of processes can be done from the Activity Monitor app as well. Also, I didn't have Homebrew installed, but the very nice article at http://coolestguidesontheplanet.com/setting-up-os-x-mavericks-and-homebrew/ took me through the process.

Thanks again

over 1 year ago ·

This command:
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Didn't work for me... It is unable to get a lock. Asks if there is another mysqld process running, but there isn't. The server seems to work even though this line doesn't.

over 1 year ago ·
4875d4370.364981 3.140x185

thx for this useful little tutorial :)

over 1 year ago ·
07a551161c3cd16b052b5c1ea0e4e6ae normal

This saved me after three days of banging my head against the wall, thanks so much...

over 1 year ago ·

Hi, can you help me fix this problem? Here is the error message that I got.

ERROR! The server quit without updating PID file (/usr/local/var/mysql/Cliffs-Mac-Pro.local.pid).

over 1 year ago ·

It's useful to fix my problem in < mysqlinstalldb --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp >, Thanks!

over 1 year ago ·
Twitter robeson

If anyone else gets errors like this:
[Warning] Can't create test file /usr/local/var/mysql/whoami.lower-test
[ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
[ERROR] InnoDB: The system tablespace must be writable!
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting

Fix permissions using these 2 commands:
sudo chown -R whoami:staff /usr/local
sudo chmod u+rwX /usr/local

Then pick up with the instructions after brew install mysql.

over 1 year ago ·
0  zc9rqty cq0gml0ka drn8a7qcplvl0r nwrbaukancmy xy1tvyc5ctsgs jx1198h0r 0ue1s

Made my life much easier. Thank you very much! - Jyothi

over 1 year ago ·

I cant tell you how many different times I installed and failed. Your clear and concise tutorial helped. Thanks for the "God Speed". He did! : )

over 1 year ago ·
P74ntgcn normal

I followed the guide but am now stuck. I keep getting the following;

Starting MySQL
ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

I've tried changing the /usr/local/bin/mysql.server file so that the basedir = /usr/local/opt/mysql .... But it does seem to work.

Any ideas?

over 1 year ago ·
C3b72b66c914881df4d3e8b4313a353c normal

Really Godspeed!
Previously installed by .dmg. Now clean installed by brew on yosemite.


over 1 year ago ·
0 5p24iok1dud9 m94blefiei ipurke94ft4bie3aqszi723zdvpqshvhla2x17cqkka62f1nvhvp

FATAL ERROR: Could not find ./bin/myprintdefaults

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

over 1 year ago ·
0 5p24iok1dud9 m94blefiei ipurke94ft4bie3aqszi723zdvpqshvhla2x17cqkka62f1nvhvp

brew install mysql
Warning: mysql-5.6.22 already installed

But there is no mysql anywhere? i deleted everything that has mysql. what is going on?

over 1 year ago ·

wonderful post, I definitely needed a fresh start on this one

over 1 year ago ·

Really helpful instruction!
Thank you!

over 1 year ago ·
386775 513400282010816 1906546753 n

Thaaaaaanks, man!

over 1 year ago ·
Q6luumom normal

YES! Perfect. Thank you so much.

over 1 year ago ·

Do you have a version of this for Yosemite? I'm in broken MySQL hell right now. :)

over 1 year ago ·

I just completed this on Yosemite and it worked just fine. I appreciate the effort to document your work and help others.

over 1 year ago ·
Cnzjgzmk normal

Very helpful. Working through teamtreehouse course and installed a second instance of mysql. mysql workbench was looking at one instance while the cmd line was seeing another. This cleared out the crap and now all are on the same install.

Thank you for the recipe.

over 1 year ago ·

Awesome!! Worked perfectly for me!

over 1 year ago ·
0 ocf8sde0c4own5tekx2xsevpvrhiq5cee5r0sew2eopri3voqk0uio0guveqbc qitdycdmpyv6m

quick question (and thanks this worked like a champ). How do I get MySQL back in the Pref Pane?

over 1 year ago ·
L9mdthid normal

Thanks, this helped.

over 1 year ago ·

Got an error,

mysqlinstalldb --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

[ERROR] unknown variable 'tmpdir=/tmp'

Any ideas?

over 1 year ago ·

I ran this on OS X El Capitan and it worked, although some of the commands failed to find / remove anything.

I think it's worth noting up front though that you will lose you databases by doing this - that didn't matter much to me thankfully.

over 1 year ago ·

"run the commands Brew suggests, add MySQL to launchctl so it automatically launches at startup"

I don't understand these instructions. Nothing resembling a suggestion came on-screen. When I try to start MySQL, I'm getting the same error I did before:

"ERROR! The server quit without updating PID file"

over 1 year ago ·
Rplzoohu normal

I had the same issue with [ERROR] unknown variable 'tmpdir=/tmp' . Did you ever found out what the issue was?

over 1 year ago ·

On OSX El Capitan I had to use

mysqld -initialize --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

instead of

mysqlinstalldb --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

for the long command. Otherwise I got the [ERROR] unknown option '--tmpdir' too

over 1 year ago ·
Ex6zgqtd normal

I spent hours trying to fix my broken install. I finally gave up and followed your guide to completely remove and re-install.
I modified it a bit, since I'm using mariadb, but otherwise perfect match for my needs.

over 1 year ago ·
0 0fii9bihmzi zsvu1nb5gvt3hnx0ygnu1nui1pz3ineyrdztpnjlgrg3six 40mrjirirtttfkvojj73nn6cop8sckvxjjl81n6hztv8wl81cfepxlkqv6ulgl77nj6lsccft8iuwyn

I got the same error "ERROR! The server quit without updating PID file (/usr/local/var/mysql/Users-MacBook-Pro.local.pid).", Can someone help me to figure out this?

over 1 year ago ·

It helped a lot, thank you!!!

over 1 year ago ·

Megathanks!!!!11 :D

over 1 year ago ·

THANK YOU!! Spent an hour trying to fix my mysql so it would talk with my CF server. THANK YOU THANK YOU!

over 1 year ago ·

Very practical approach, thank you!

over 1 year ago ·

I just made an account to thank you: thank you for writing this. I've been going through a Laracast video tutorial, somehow completely messed up my mysql installation, and was absurdly lost. This is a godsend. Thank you.

9 months ago ·

its showing an error that

unknown variable 'tmpdir=/tmp'

please help me fix this

8 months ago ·

After running into the following errors (relatively common, from what I can tell), this was the correct resolution to my issue.
Errors this resolved:
error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock' mysql_install_db is deprecated. Please consider switching to mysqld --initialize -bash: mysql_install_db --verbose --user=root --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --tmpdir=/tmp: No such file or directory

7 months ago ·
Filed Under