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 lineMYSQLCOM=-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.
Written by Cory Simmons
Related protips
46 Responses
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.
Oops, it was there but because of the backticks in the command markdown was breaking.
You sir, are a gentleman and a scholar. You have now enabled me to actually start working again :D
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!
<3 !
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!
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.
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
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.
thx for this useful little tutorial :)
This saved me after three days of banging my head against the wall, thanks so much...
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).
It's useful to fix my problem in < mysqlinstalldb --verbose --user=whoami
--basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp >, Thanks!
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
.
Made my life much easier. Thank you very much! - Jyothi
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! : )
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?
Really Godspeed!
Previously installed by .dmg. Now clean installed by brew on yosemite.
Thanks
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.
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?
wonderful post, I definitely needed a fresh start on this one
Really helpful instruction!
Thank you!
Thaaaaaanks, man!
YES! Perfect. Thank you so much.
Do you have a version of this for Yosemite? I'm in broken MySQL hell right now. :)
I just completed this on Yosemite and it worked just fine. I appreciate the effort to document your work and help others.
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.
Awesome!! Worked perfectly for me!
quick question (and thanks this worked like a champ). How do I get MySQL back in the Pref Pane?
Thanks, this helped.
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?
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.
"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"
I had the same issue with [ERROR] unknown variable 'tmpdir=/tmp' . Did you ever found out what the issue was?
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
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.
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?
It helped a lot, thank you!!!
Megathanks!!!!11 :D
THANK YOU!! Spent an hour trying to fix my mysql so it would talk with my CF server. THANK YOU THANK YOU!
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.
its showing an error that
unknown variable 'tmpdir=/tmp'
please help me fix this
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
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.
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).
Spent half a day trying to resolve "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" on MacOS Catalina.
Following these steps resolved the issue and mysql is now running and accessible.