Brew Install Mysql On MacOS
Answer :
I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus:
Used brew's remove & cleanup commands, unloaded the launchctl script, then deleted the mysql directory in /usr/local/var, deleted my existing /etc/my.cnf (leave that one up to you, should it apply) and launchctl plist
Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.
Step-by-step:
brew remove mysql brew cleanup launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist sudo rm -rf /usr/local/var/mysql I then started from scratch:
- installed mysql with
brew install mysql ran the commands brew suggested: (see note: below)
unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmpStart mysql with
mysql.server startcommand, to be able to log on itUsed the alternate security script:
/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installationFollowed the
launchctlsection from the brew package script output such as,#start launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist #stop launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Note: the --force bit on brew cleanup will also cleanup outdated kegs, think it's a new-ish homebrew feature.
Note the second: a commenter says step 2 is not required. I don't want to test it, so YMMV!
Here are detailed instructions combining getting rid of all MySQL from your Mac then installing it The Brew Way as Sedorner wrote above:
Remove MySQL completely per The Tech Lab
ps -ax | grep mysql- stop and
killany MySQL processes sudo rm /usr/local/mysqlsudo rm -rf /usr/local/var/mysqlsudo rm -rf /usr/local/mysql*sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plistsudo rm -rf /Library/StartupItems/MySQLCOMsudo rm -rf /Library/PreferencePanes/My*launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist- edit
/etc/hostconfigand 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*sudo rm -rf /tmp/mysql*- try to run
mysql, it shouldn't work
Brew install MySQL per user Sedorner from this StackOverflow answer
brew doctorand fix any errorsbrew remove mysqlbrew cleanupbrew updatebrew install mysqlunset TMPDIRmysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp # whoami is executed inlinemysql.server startrun the commands Brew suggests, add MySQL to
launchctlso it automatically launches at startup
mysql should now work and be running all the time as expected
Godspeed.
Had the same problem. Seems like there is something wrong with the set up instructions or the initial tables that are being created. This is how I got mysqld running on my machine.
If the mysqld server is already running on your Mac, stop it first with:
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
Start the mysqld server with the following command which lets anyone log in with full permissions.
mysqld_safe --skip-grant-tables
Then run mysql -u root which should now let you log in successfully without a password. The following command should reset all the root passwords.
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
Now if you kill the running copy of mysqld_safe and start it up again without the skip-grant-tables option, you should be able to log in with mysql -u root -p and the new password you just set.
Comments
Post a Comment