Reputation: 1473
So I installed mysql
through brew
, and I installed 2 versions on my Mac OS -
mysql 5.7
mysql 8.0
I brew link
'ed to 5.7, so if I type mysql --version
, it gives me distro 5.7.26
.
The problem is here. Right now if I type brew services list
, there are
two services mysql stopped
and [email protected] stopped
If I brew services start mysql
, then I sudo mysql
in the Terminal, I can connect to mysql server. But it shows the server instance is 8.0
. Well, I guess unlike command line, brew services start XXX
would not pick up the linked XXX
If I brew services start [email protected]
, and I sudo mysql
, it would not connect successfully. It gives me the error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I think it means the mysql client does not find an active open instance.
How to connect to an older version of local mysql instance?
Upvotes: 8
Views: 5855
Reputation: 1473
Well, resolved myself after 2 days effort.
The solution is that, if I want to run a local mysql 5.7
instance, I need to completely remove any system mysql 8.0
. and mysql 5.7
folder, as well as remove formulas from brew
Finally reinstall only mysql 5.7
.
First uninstall all versions.
brew uninstall mysql
brew uninstall [email protected]
Then remove remaining detritus.
For intel:
rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf
Alternatively for Apple Silicon:
rm -rf /opt/homebrew/var/mysql/
rm /opt/homebrew/etc/my.cnf
Then reinstall, link, and start the service.
brew install [email protected]
brew link --force [email protected]
brew services start [email protected]
Additionally, on Apple Silicon, if you get an error like this:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
when connecting with mysql -uroot
to the just started server, try using MySQL's packaged server start tool:
brew services stop [email protected]
mysql.server start
mysql -uroot
as found in https://medium.com/@at0dd/install-mysql-5-7-on-mac-os-mojave-cd07ec936034
Upvotes: 9