ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac
Posted
技术标签:
【中文标题】ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket \'/tmp/mysql.sock\' (2) on Mac Big Sur【英文标题】:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac Big SurERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac Big Sur 【发布时间】:2021-03-31 16:58:51 【问题描述】:我刚升级到 MacOS Big Sur,发现无法使用mysql -u root
(无密码)登录 mysql 控制台。
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
我用 brew 安装了 MariaDB (brew install mariadb
)
我检查了mysql守护进程,发现如下错误
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
这里是/usr/local/var/mysql/
的权限
drwxr-xr-x 68 xuan admin 2176 21 Dec 15:48 mysql
套接字文件位置
Xuans-MacBook-Pro:xuan$ mysqld --help --verbose | grep sock
socket /tmp/mysql.sock
unix-socket ON
有什么建议吗?
【问题讨论】:
aria相关的错误只针对mariadb,所以这个问题不适用于mysql。 我也升级到了 big sur,我也遇到了同样的问题,尽管 mariaDB 没有。当我尝试做 rails s puma 时,会弹出此错误。sudo mysql -uroot
抛出同样的错误
【参考方案1】:
我在运行 big sur 11.1 的 i9 的 2018 macbook pro 上遇到了同样的问题 我可以使用 mysql workbench 和 datagrip 链接到 mysql 数据库,但是当我尝试从终端访问 mysql 时,我得到“无法通过套接字连接到本地 MYSQL 服务器”。 我回到 /usr/local/mysql/bin 并运行 ./mysql -u root -p 并连接。 这是一个很大的安全问题吗? MAMP 正在运行。 MYSQL 编辑器行为正常。似乎 big sur 不允许套接字通过 MAMP 连接。
【讨论】:
【参考方案2】:通过套接字以root用户身份登录要求套接字的所有者是root,而不是任何其他用户,因为身份验证将通过unix套接字身份验证执行。
所以一个简单的sudo mysql -uroot
应该可以工作。
【讨论】:
以上是关于ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac 的主要内容,如果未能解决你的问题,请参考以下文章
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac
ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/run/mysqld/mysqld.sock'
FreeBSD ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when I
尝试了一切仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (
尝试了一切仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (