go here: https://superuser.com/a/400345/981705 (text pasted at the end of this gist)
for further research: https://stackoverflow.com/questions/31413728/connect-mysql-through-localhost-not-working-but-127-0-0-1-is-working
https://stackoverflow.com/questions/10757169/location-of-my-cnf-file-on-macos
on macOS, you'll probably find your my.cnf file in: /usr/local/etc/my.cnf
but you can find out where it might be with: mysql --verbose --help | grep my.cnf https://stackoverflow.com/a/10757261/3044358
-
Open the Terminal
-
Use
mysqldump
to backup your databases -
Check for MySQL processes with:
ps -ax | grep mysql
-
Stop and kill any MySQL processes
-
Analyze MySQL on HomeBrew:
brew remove mysql brew cleanup
-
Remove files:
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*
-
Unload previous MySQL Auto-Login:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
-
Remove previous MySQL Configuration:
code /etc/hostconfig # Remove the line MYSQLCOM=-YES-
-
Remove previous MySQL Preferences:
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
if you just need to handle removing a password that is mysteriously present, even after reinstall, do this:
Your mysql install is just complaining that you can't connect to the instance on mysql locally as root without using a password. If you forgot the password or don't know what it is, you can reset it as follows:
Kill the current mysql process running (do a ps -efc| more) or something and kill anything that says MySQL with kill <process_id>. A better alternative is to try and simply stop the process gracefully with rcmysql stop
Create a file (ideally in a directory that only root can read) called init.txt with the following text:
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
Launch MySQL in safe mode and passing the init.txt file as parameter as so:
mysqld_safe --init-file=mysql-init.txt &
Now you can kill MySQL once again and restart the service normally (I think Suse uses rcmysql start:
rcmysql start
Connect to the server as you'd normarlly do with:
mysql -u root@localhost -p