原来如此简单:解决Mac上的Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mac os上第一次使用mysql,果然出现了问题,安装好mysql的dmg后,在终端输入mysql,结果出现

hrfpc:~ hrf$ mysql

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

这个错误

在网上搜到很多方法,不好使,然后查询了官方文档

http://dev.mysql.com/doc/refman/5.7/en/can-not-connect-to-server.html

下面写道

Here are some reasons the Can't connect to local MySQL server error might occur:

  • mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present.

  • 。。。
没想到第一条就符合,然后我尝试输入mysqld

结果

hrfpc:~ hrf$ mysqld

mysqld: Can't change dir to '/usr/local/mysql-5.7.16-osx10.11-x86_64/data/' (Errcode: 13 - Permission denied)

等一大串错误之类的 ,最后退出了

最后,正确的方法:

hrfpc:~ hrf$ sudo mysqld_safe

2016-10-14T11:47:17.6NZ mysqld_safe Logging to '/usr/local/mysql/data/hrfpc.err'.

2016-10-14T11:47:17.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

然后mysqld服务就运行啦


此时,终于能够打开mysql:


hrfpc:etc hrf$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 5.7.16


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


有时事情总是用最简单的办法解决



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值