mac brew install mysql ‘/tmp/mysql.sock’ (2) [How to Solve]

the reason for the error is very simple: MySQL should be used instead of MySQL when starting the command server

mac brew install mysql

Install MySQL with homebrew on Mac to perfectly solve error 2002 (HY000):

Can’t connect to local MySQL server through socket ‘/tmp/mysql.Sock ‘(2) error

1. Start the command mysql server

the startup method of using MySQL command directly is wrong

This problem occurs when you directly call the MySQL command. It is said on the Internet that it is because of MySQL Caused by CNF configuration file.

the correct startup method is mysql server

➜  support-files mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
➜  support-files pwd
/opt/homebrew/opt/mysql/support-files
➜  support-files ls
mysql-log-rotate    mysql.server        mysqld_multi.server

2. my.CNF file location

my.CNF file location

➜  homebrew cd etc
➜  etc ls
bash_completion.d   ca-certificates     dump.rdb            my.cnf              [email protected]         
redis-sentinel.conf redis.conf
➜  etc pwd
/opt/homebrew/etc

3. MySQL installation location

➜  homebrew cd opt
➜  opt ls
ca-certificates jasper          libevent        libpng          lz4             [email protected]     pzstd           six
devil           jpeg            libjpeg         libtiff         mysql           protobuf        redis           zlib
icu4c           lcms2           libjpg          little-cms2     [email protected]       [email protected]   [email protected]6.2       zstd
➜  opt cd mysql
➜  mysql ls
INSTALL_RECEIPT.json      LICENSE.router            README.router             homebrew.mxcl.mysql.plist lib                       support-files
LICENSE                   README                    bin                       homebrew.mysql.service    mysqlrouter-log-rotate
LICENSE-test              README-test               docs                      include                   share
➜  mysql pwd
/opt/homebrew/opt/mysql
➜  mysql

Read More: