os6woq
Last Updated: July 13, 2017
·
148.7K
· 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

Godspeed.

Say Thanks
Respond

43 Responses
Add your response

13709
0d73ef76716c03756f7fc78be7bf87c3

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 ·
13711
Cory simmons 700

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

over 1 year ago ·
14623
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 ·
14659
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 ·
14687
E2c47e988e5bdc83cc29a24fb872edc8

<3 !

over 1 year ago ·
14814
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 ·
15200
9a7a241b2c2c226655bba7b50c386973

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 ·
15379
3a51bd47880a54963786ee1a643a0d7b

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 ·
16019
780bd621fc8dd496f89ffd2b5f141296

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 ·
16388
4875d4370.364981 3.140x185

thx for this useful little tutorial :)

over 1 year ago ·
16433
07a551161c3cd16b052b5c1ea0e4e6ae normal

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

over 1 year ago ·
16997
None

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 ·
17009
None

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 ·
17054
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 ·
17120
0  zc9rqty cq0gml0ka drn8a7qcplvl0r nwrbaukancmy xy1tvyc5ctsgs jx1198h0r 0ue1s

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

over 1 year ago ·
17211
None

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 ·
17523
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 ·
17798
C3b72b66c914881df4d3e8b4313a353c normal

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

Thanks

over 1 year ago ·
17899
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 ·
17900
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 ·
18124
124e2c51ec2f05a76d94e79fd466645e

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

over 1 year ago ·
18309
None

Really helpful instruction!
Thank you!

over 1 year ago ·
19500
386775 513400282010816 1906546753 n

Thaaaaaanks, man!

over 1 year ago ·
19836
Q6luumom normal

YES! Perfect. Thank you so much.

over 1 year ago ·
20121
B719b0deb1c780aac07872f3e9d3d4b3

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

over 1 year ago ·
20747
None

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 ·
21251
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 ·
21838
None

Awesome!! Worked perfectly for me!

over 1 year ago ·
22870
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 ·
24700
L9mdthid normal

Thanks, this helped.

over 1 year ago ·
24969
None

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 ·
24979
None

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 ·
25207
None

"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 ·
25215
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 ·
25234
None

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 ·
26275
Ex6zgqtd normal

Thanks!
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 ·
26482
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 ·
26606
None

It helped a lot, thank you!!!

over 1 year ago ·
27492

Megathanks!!!!11 :D

over 1 year ago ·
27849

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 ·
28127

Very practical approach, thank you!

12 months ago ·
29012

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.

2 months ago ·
29095

its showing an error that

unknown variable 'tmpdir=/tmp'

please help me fix this

about 1 month ago ·
Filed Under

Awesome Job

73e4bca6 7d15 11e7 9be9 be2b6a600c3a
Sr. Site Reliability Engineer
·
Emeryville, CA & San Francisco, CA
·
Full Time