Skip to content

Instantly share code, notes, and snippets.

@vitorbritto
Last active April 9, 2024 14:26
Show Gist options
  • Save vitorbritto/0555879fe4414d18569d to your computer and use it in GitHub Desktop.
Save vitorbritto/0555879fe4414d18569d to your computer and use it in GitHub Desktop.
Remove MySQL completely from Mac OSX

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:

    # Edit this file: /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

Remove MySQL completely (Apple Silicon Version)

  • brew remove mysql
  • rm -rf /opt/homebrew/var/mysql
  • brew install mysql
  • mysql.server start
  • mysql -uroot
@tnorthcutt
Copy link

This was very helpful. I also had to do:

rm /usr/local/etc/my.cnf

Something I had done previously had resulted in a my.cnf file that prevented MySQL from working (I was getting the dreaded ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error).

@annstringer
Copy link

This helped. I also had the ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) and also had to remove rm /usr/local/etc/my.cnf.

Thanks.

@genorchiomento
Copy link

Thanks bro! This helped

@HimanshuLuthra
Copy link

Do reboot else it wont work

@brendanfalkowski
Copy link

This helped immensely a couple months ago, and I finally went back to document the fix in my field manuals for Homebrew and Valet Plus:

@AlaaKho
Copy link

AlaaKho commented Jul 21, 2019

I did all the process and worked then I installed again the mysql

$ brew install mysql
$ brew tap homebrew/services
$ brew services run mysql

And everything start work until today, where I tried to run my local website (as any other day) and I got:

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

After that, every answer that I tried takes me to another error and so on. This is not the first time that happened and the only solution is re-install everything. So I was wondering if anyone have any idea why this could be happening. I don't want to run the entire process every time that mysql decide crash, but I want fix the problem or at least understand what is going on.
sequelize/cli#572

hey dear you can fix your problem by running
mysql.server start

Has anyone managed to solve this? This happened suddenly to me, and mysql server became unstable, and I couldn't connect to it (giving the same error mentioned).? and would I face this still even if I reinstalled?

@dannguyen
Copy link

Regarding Step 6:

sudo rm -rf /Library/PreferencePanes/My*

Is it necessary to use such a wildcard here, instead of a more explicit pattern? MySQL can't be the only thing (now, or in the future) that a user might have in /Library/PreferencePanes that begins with My, right?

@aravindcf
Copy link

Thanks a lot. I followed the same procedure. But when I typed mysql I was getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'. I used sudo rm -rf /usr/local/bin/mysql*. That worked.

@QubeChan
Copy link

Can you clarify on step 4? I try killing the process but it mysqld won't die it'll show up under a new id

@brendanfalkowski
Copy link

@QubeChan — I had the some problem. Documented here: https://manuals.gravitydept.com/develop/command-line/brew

I skipped it and didn't have issues with the remaining steps.

@crmpicco
Copy link

Thanks for posting

@sandokan815
Copy link

It saved my many days. thanks

@yogesh-desai
Copy link

Thank you. Great post! Saved a lot of time

@Yigaue
Copy link

Yigaue commented Jan 14, 2020

Good post. I defaulted to install DBngin and it worked for me.

@callump5
Copy link

Thanks this got it all working!

@brunofariasdeo
Copy link

Helped a lot, thank you!

@Anishmourya
Copy link

After long searching , i solved this issue , downloaded official mac os community file from :- https://dev.mysql.com/downloads/file/?id=492745
it worked for mac os Catalina 10.15 , check this link :- https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html , they also mentioned required packages to run mysql on mac os , specially "/tmp/mysql.sock" at bottom .

@cjstage
Copy link

cjstage commented Apr 6, 2020

Saved my behind.

@dannydickson
Copy link

This was very helpful. I also had to do:

rm /usr/local/etc/my.cnf

Something I had done previously had resulted in a my.cnf file that prevented MySQL from working (I was getting the dreaded ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error).

Apparently, this config file can live in several places: /etc/my.cnf, OR /etc/mysql/my.cnf OR ~/.my.cnf. My particular install had placed it at /etc/my.cnf as well, but thought I'd drop the other options here in case anybody else is down this same rabbit hole as me one day.

Thanks to OP @vitorbritto for the great gist as well!

@vishwarajanand
Copy link

Thanks, it worked :-)

@vycz
Copy link

vycz commented May 14, 2020

Thanks

@ronaksahai
Copy link

how do we do step 8... removing the line part

@spmaniusa-hub
Copy link

Thanks a lot. It would have been good if I got this article first. I would have saved about 5 hours :-(

@msidana
Copy link

msidana commented Jul 6, 2020

Thank you so much. I wish I had landed up on this page much earlier. I struggled so much. This is an excellent page, Thanks 👍

@sammyrTX
Copy link

Thank you! Very helpful!

@swashata
Copy link

Thank you very much. It is notoriously difficult to uninstall mysql data. Your tutorial did the trick! 👍

@lexjacobs
Copy link

subl /etc/hostconfig`
has a hanging backtick

@mkomigor
Copy link

👍

@sreekanth-a1
Copy link

thank you very much

@elgcv
Copy link

elgcv commented Sep 24, 2020

Thank you , it's help a lot !

@FahimAnayet
Copy link

Aaah, Thanks man!

@derins
Copy link

derins commented Oct 12, 2020

Thank you

@froxtrox
Copy link

Nice work! Thank you

@commadelimited
Copy link

subl /etc/hostconfig`
has a hanging backtick

Also, not everyone has sublime text. Better to simply say "edit this file".

@SorosWen
Copy link

This is very helpful! Thank you!

@CaReS0107
Copy link

On the Apple Silicon:

brew remove mysql
rm -rf /opt/homebrew/var/mysql
brew install mysql
mysql.server start
mysql -uroot

@vitorbritto
Copy link
Author

vitorbritto commented May 10, 2021

subl /etc/hostconfig`
has a hanging backtick

Also, not everyone has sublime text. Better to simply say "edit this file".

Thanks @commadelimited, gist updated.

@vitorbritto
Copy link
Author

subl /etc/hostconfig`
has a hanging backtick

Thanks @lexjacobs, gist updated.

@seemly
Copy link

seemly commented May 24, 2021

When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:

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

My fix was to modify the MySQL config file:

nano /usr/local/etc/my.cnf

Append the following lines:

tmpdir=/tmp
user=root

Then run:

brew services restart mysql@5.7

This fixed my issue, and I was then able to connect successfully with my DB client.

@Eddievin
Copy link

@seemly Thanks for this

@HusseinMalingha
Copy link

Thanks <3

@KalisaFalzone
Copy link

This was very helpful. I also had to do:

rm /usr/local/etc/my.cnf

Something I had done previously had resulted in a my.cnf file that prevented MySQL from working (I was getting the dreaded ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error).

Thank you! This was what I needed!

@iRiziya
Copy link

iRiziya commented Jan 5, 2022

Awesome Thanks 😊🙌🏻

@keomony
Copy link

keomony commented Jan 25, 2022

saved my day! Thank you :)

@ingmarrr
Copy link

ingmarrr commented Mar 4, 2022

Thank god for your beautiful ass mate, I was looking for this for like an hour

@zhafed
Copy link

zhafed commented Apr 11, 2022

Append the following lines to:

  • /opt/homebrew/etc/my.cnf

  • /opt/homebrew/Cellar/mysql@5.7/5.7.37/.bottle/etc/my.cnf

tmpdir=/tmp
user=root

Thanks @seemly it's worked , i spend 8 hours searching .

@seemly you saved me with these Comment : here

@bantya
Copy link

bantya commented Jun 4, 2022

Thanks for this awesome guide.
@tnorthcutt's reply helped a lot!

@rebek73
Copy link

rebek73 commented Jun 29, 2022

Thanks, it worked!!

@mkomigor
Copy link

mkomigor commented Jul 1, 2022

Thanks

@TienPV-ROR
Copy link

nice

@SaimumIslam
Copy link

sudo rm -rf /opt/homebrew/etc/my.cnf

does the trick for me

@YUN-RU-TSENG
Copy link

YUN-RU-TSENG commented Nov 29, 2022

it works, i remove MySQL 8 successfully.
Thanks

@SeFeX
Copy link

SeFeX commented Dec 7, 2022

When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:

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

My fix was to modify the MySQL config file:

nano /usr/local/etc/my.cnf

Append the following lines:

tmpdir=/tmp
user=root

Then run:

brew services restart mysql@5.7

This fixed my issue, and I was then able to connect successfully with my DB client.

This works!

@websterl3o
Copy link

On the Apple Silicon:

brew remove mysql
rm -rf /opt/homebrew/var/mysql
brew install mysql
mysql.server start
mysql -uroot

just running this already fixed it for me

@BranchDev110
Copy link

I installed mysql v5 through package.
How can I uninstall that?

@mhbaando
Copy link

Thanks it worked for me

@ArifaAbid
Copy link

Thanks, it help a lot

@Thlenzi
Copy link

Thlenzi commented Oct 13, 2023

Great Job!!! It worked for me !!!

@nghitruongdev
Copy link

Thanks, it worked!

@AldianBaim
Copy link

Thank you very much, finnaly this method is solved my problem!

@wltrallen2
Copy link

OMG! Needed this for hours. Finally found this. Thank you!

@Kiansaziz
Copy link

Thnaks, it worked !

@martris
Copy link

martris commented Mar 15, 2024

brew remove mysql rm -rf /opt/homebrew/var/mysql brew install mysql mysql.server start mysql -uroot
this would work , but I noticed that there is another version of mysql on my mac:
> mysql -V mysql Ver 14.14 Distrib 5.7.24, for osx11.1 (x86_64) using EditLine wrapper
Later use this command :type -a mysql
It shows that anaconda3 installed a old version automatically.Ops....
mysql is /opt/anaconda3/bin/mysql
Remove it , then reinstall.

@andragri
Copy link

andragri commented Apr 8, 2024

@seemly god bless you! I spend about 8 hours to look for an answer that could help me

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