'Homebrew - brew mysql 8 - Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I tried a lot to install MySQL8 via Homebrew on Mac 10.14.5. I was running MySQL 5.7 before that and did the following: I removed MySQL completely via this tutorial: https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks

After that I run mysql and got the message that the command was not known. So I installed mysql with brew install mysql. After installation I did brew link --force mysql and got Warning: Already linked: /usr/local/Cellar/mysql/8.0.19

I edited /usr/local/etc/my.cnf and added default-authentication-plugin=mysql_native_password in the [mysqld] section. After that I restartet the service using brew services restart mysql

brew services list shows me this now:

mysql         started root   /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
[email protected]     stopped

However, when I type mysql in the terminal I get this:

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

The /tmp/mysql.sock does not exist.

When I change the host in the my.cnf file from localhost to 127.0.0.1 this error will change into this:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 54

Anyone has an idea what's going on here and how I can fix it? I also googled it and found various Threads, some are saying that the permissions must be changed to this sudo chown -R _mysql:mysql /usr/local/var/mysql but this does not change anything in my case.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source