Search code examples
mysqlmacoshomebrewapple-m1

MySQL installed via HomeBrew Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


I've been searching for hours about this issue i'm having.

I have installed [email protected] in my mac osx Monterey 12.0.1 with M1 chip using Homebrew.

I've been following this tutorial that helped me install mysql version 5.7. I'm specifying this version because i'm recreating a production environment on local.

At the step where I need to secure my mysql installation I type user root password and get this error Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).

I have read many ways to fixing this but I can't make it work with any of those because most of them don't relate to homebrew or don't work well for me.

I have the service running using the brew services start [email protected] command and this doesn't seem fixing the issue.

Is there any possibility I can't make it run because I have an M1 chip?


Solution

  • I researched again and remembered that I had previously installed a MySQL 8.X version. I uninstalled it only using the brew uninstall command. This wasn't enough and I made sure I deleted all the mysql related files and folders from my computer.

    After that I retried installing MySQL 5.7 as a completely fresh install. Then at this same step where I had trouble before I didn't have any issue, I followed the installation and now is up and running.

    These are all the files I found were related to other MySQL installations, you may or may not have them in your system but I suggest to try delete them all, here I paste the commands needed:

    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 line MYSQLCOM=-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* 
    /opt/homebrew/var/mysql
    /opt/homebrew/etc/my.cnf