Skip to content

Instantly share code, notes, and snippets.

@lexjacobs
Forked from vitorbritto/rm_mysql.md
Last active June 18, 2022 21:47
Show Gist options
  • Save lexjacobs/9e2d5540c52168ee88c81a9755102657 to your computer and use it in GitHub Desktop.
Save lexjacobs/9e2d5540c52168ee88c81a9755102657 to your computer and use it in GitHub Desktop.
Remove MySQL completely from Mac OSX

just need to handle there being a password mysteriously present, even after reinstall?

go here: https://superuser.com/a/400345/981705 (text pasted at the end of this gist)

missing my.cnf file (leads to localhost binding errors):

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

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    brew cleanup
    
  6. 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*
    
  7. Unload previous MySQL Auto-Login:

    launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    
  8. Remove previous MySQL Configuration:

    code /etc/hostconfig
    # Remove the line MYSQLCOM=-YES-
    
  9. 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*
    
  10. Restart your computer just to ensure any MySQL processes are killed

  11. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment