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:
结果
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.
有时事情总是用最简单的办法解决