1

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

I have installed mysql@5.7 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 mysql@5.7 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?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Francesc Roca
  • 121
  • 3
  • 12

2 Answers2

3

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
Francesc Roca
  • 121
  • 3
  • 12
0

Do you have the mysql.sock in your /tmp?

You can make a symlink, depending on your installation

ln -s /var/mysql/mysql.sock /tmp/mysql.sock
Honsa Stunna
  • 577
  • 2
  • 8
  • 24
  • As I used homebrew, I assume the installation path is /opt/homebrew/opt/mysql@5.7 , I can't find mysql.sock anywhere inside this directory – Francesc Roca Nov 24 '21 at 11:08
  • Search it on your system and link it in your tmp as work around – Honsa Stunna Nov 24 '21 at 13:50
  • I have found a file called mysql.sock.lock, is this the file i'm looking for? – Francesc Roca Nov 24 '21 at 14:31
  • No, remove that .lock file and restart mysql, it should generate a new mysql.sock – Honsa Stunna Nov 24 '21 at 14:48
  • I just searched where is that file located and turns out it's from an old folder I didn't knew about it. I deleted it just in case and restarted mysql, they aren't related and doesn't seem to create any file named mysql.sock anywhere in the computer – Francesc Roca Nov 24 '21 at 15:05
  • https://www.hivelocity.net/kb/what-to-do-if-mysql-sock-file-is-missing/ – Honsa Stunna Nov 24 '21 at 15:10
  • 1
    Thanks for the link. I finally solved the issue. What happened was that I previously had installed mysql 8 in my machine, I did the brew uninstall but that wasn't enough to get rid of all the files from the previous install. I had to remove them by hand and then install mysql 5.7. That solved the issue. – Francesc Roca Nov 25 '21 at 08:39