0

I am running a Mac on Monterey v 12.4 with an M1 Max. I tried to install mysql on my Mac but I never get it to work regardless what I do. The first thing I tried to do is:

$ brew install mysql

Then I start the server:

$ brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

But when I try to execute the following command or any other mysql cli command:

$ mysql_secure_installation

I always get the following error:

Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I've tried every possible fix I could find on the internet but nothing works.

I then tried to install the community server from the mysql website. It shows me in the settings it it's running properly, but I can't connect to the Server. Neither using the workbench nor the cli. So I removed it again.

I also did brew doctor and fixed the issues.

I am really desperate to get the mysql server running for local programming and would appreciate any help! Thanks in advance!

1
  • Did you have a chance to verify that the socket file location is set correctly for both the server and the client?
    – mustaccio
    Commented Sep 11, 2022 at 12:20

1 Answer 1

0

I had the same issue with Monterey trying to get mysql to work...

What worked for me was to do a deep cleanup...

You can check these great instructions to cleanup if the way I did it bellow does not work for you: mysql cleanup OSX

Used brew remove mysql and brew remove [email protected] ...etc for all mysql versions I might have installed before including mariadb brew remove mariadb

Then cleanup brew cleanup

The removed manually these files/folders

rm /opt/homebrew/etc/my.cnf
rm -rf opt/homebrew/etc/my.cnf.d
rm /opt/homebrew/etc/my.cnf.default

Then backup any database you had and remove the /opt/homebrew/var/mysql/ folder to start fresh

cp -R /opt/homebrew/var/mysql /opt/homebrew/var/mysql_bak
rm -rf /opt/homebrew/var/mysql

Once all cleaned up I rebooted my machine

Then installed mysql brew install mysql or brew install [email protected] depending on which version you want...

Then make sure the mysql service is running: brew services list should show you this:

mysql   started root    ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

If the mysql service is not started, try to start it manually: brew services start mysql or if you installed [email protected], do this brew services start [email protected]

If it does not want to start:

brew services stop mysql
brew services stop [email protected]
brew unlink mysql
brew unlink [email protected]

Then link: brew link --force --overwrite mysql or if you installed [email protected], do this brew link --force --overwrite [email protected]

Then try again: brew services start mysql or if you installed [email protected], do this brew services start [email protected]

Hope this helps and if what you are looking for is to run multiple mysql versions at the same time then you'll need different database location configuration to avoid conflicts... this is the best tutorial I know: Multiple MySQL versions on MacOS with Homebrew

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.