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

Viewed 1560

I just upgraded to MacOS Big Sur, and I found out I can't login to mysql console with mysql -u root (without password).

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

I installed MariaDB with brew (brew install mariadb)

I checked the mysql daemon, and found following error

Xuans-MacBook-Pro:~ xuan$ mysqld
2020-12-21 15:46:27 0 [Note] mysqld (mysqld 10.5.8-MariaDB) starting as process 2091 ...
2020-12-21 15:46:27 0 [Warning] Can't create test file /usr/local/var/mysql/Xuans-MacBook-Pro-2.lower-test
2020-12-21 15:46:27 0 [ERROR] mysqld: File '/usr/local/var/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")
2020-12-21 15:46:27 0 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/usr/local/var/mysql/aria_log_control'
2020-12-21 15:46:27 0 [ERROR] Plugin 'Aria' init function returned error.
2020-12-21 15:46:27 0 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
2020-12-21 15:46:27 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-12-21 15:46:27 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-12-21 15:46:27 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-12-21 15:46:27 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-12-21 15:46:27 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-12-21 15:46:27 0 [ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
2020-12-21 15:46:27 0 [ERROR] Failed to initialize plugins.
2020-12-21 15:46:27 0 [ERROR] Aborting

Here is the permission of /usr/local/var/mysql/

drwxr-xr-x  68 xuan  admin  2176 21 Dec 15:48 mysql

socket file location

Xuans-MacBook-Pro:xuan$ mysqld --help --verbose | grep sock
socket                                                       /tmp/mysql.sock
unix-socket                                                  ON

Any suggestions?

2 Answers

I had this same issue on a 2018 macbook pro with an i9 running big sur 11.1 I could link to a mysql database with mysql workbench and datagrip no problem but when I tried to access mysql from the terminal i got "can't connect to local MYSQL server through socket." I dropped back to the /usr/local/mysql/bin and ran ./mysql -u root -p and it connects. Is this a big sur security issue? MAMP is running. The MYSQL editors act normal. It seems big sur will not allow the socket connect through MAMP.

Login as user root via socket requires that the owner of the socket is root, not any other user, since authentication will performed via unix socket authentication.

so a simple sudo mysql -uroot should work.

Related