利用Homebrew安装完Mysql后,利用mysql -u root缺省模式启动,提示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

另外安装完之后会有提示,可以看到如下:

/usr/local/Cellar/mysql/5.7.9/bin/mysqld --initialize-insecure --user=comet

We've installed your MySQL database without a root password. To secure it run:mysql_secure_installation

这个时候说明homebrew已经自动初始化过一次mysql了,我们用mysql_secure_installation来进行密码初始化。但是输入密码后依旧这么提示:

Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

提示找不到/tmp/mysql.sock这个文件,我们手动启动mysql.server:

mysql.server start

提示依旧…..(:з」∠),最后经过各种查google,绕了一大圈之后,发现只要很简单的处理权限问题:

/usr/local/var 下有 mysql目录,对其进行授权,确保属于mysql自身

mysql error

Start Success!

如果还是无法正常启动,尝试如下方法:

1
sudo chmod -R 777 /usr/local/var/mysql/