os6woq
Last Updated: November 08, 2018
·
204.6K
· corysimmons

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.

46 Responses
Add your response

13709

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

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

over 1 year ago ·
14623

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

over 1 year ago ·
14659

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

<3 !

over 1 year ago ·
14814

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

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

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

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

thx for this useful little tutorial :)

over 1 year ago ·
16433

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

over 1 year ago ·
16997

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

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

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

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

over 1 year ago ·
17211

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

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

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

Thanks

over 1 year ago ·
17899

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

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

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

over 1 year ago ·
18309

Really helpful instruction!
Thank you!

over 1 year ago ·
19500

Thaaaaaanks, man!

over 1 year ago ·
19836

YES! Perfect. Thank you so much.

over 1 year ago ·
20121

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

over 1 year ago ·
20747

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

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

Awesome!! Worked perfectly for me!

over 1 year ago ·
22870

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

over 1 year ago ·
24700

Thanks, this helped.

over 1 year ago ·
24969

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

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

"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

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

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

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

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

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!

over 1 year 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.

over 1 year ago ·
29095

its showing an error that

unknown variable 'tmpdir=/tmp'

please help me fix this

over 1 year ago ·
29250

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

over 1 year ago ·
30853

Total lifesaver. I had been struggling with issues with MySql for over a week. Now I have a fresh and clean MySql installation on my machine. Thank you so much! Many +1s to you.

4 months ago ·
31166

Nope. Destroyed my environment, reinstalled, and am still getting this:

mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/myComputerName.local.pid).

2 months ago ·