背景:
许久不打开本地mysql连接,今天突然连接不上了,报错:
➜ ~ mysql -version ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
过程:
百度都说是mysql.sock的文件,建议把 /tmp下的两个文件干掉就好了,但感觉跟我的问题没多大关系,看到很多人说不知道在哪里去找sock文件,mac系统其实用find命令就好了,
➜ ~ find / -name mysql.sock find: /usr/sbin/authserver: Permission denied find: /usr/local/var/run/nginx/scgi_temp: Permission denied find: /usr/local/var/run/nginx/uwsgi_temp: Permission denied find: /usr/local/var/run/nginx/proxy_temp: Permission denied find: /usr/local/var/run/nginx/fastcgi_temp: Permission denied find: /usr/local/var/run/nginx/client_body_temp: Permission denied find: /.Spotlight-V100: Permission denied find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
然后许多人说不知道怎么更改,其实可以这么改,根据上面find找到sock目录后,假如:
➜ ~ find / -name mysql.sock /var/lib/mysql/mysql.sock 目录在/var/lib/mysql/mysql.sock这个位置,则需要修改my.cnf文件 ➜ ~ vi /usr/local/mysql/my.cnf [client] character-set-server = utf8 port = 3306 socket = /var/lib/mysql/mysql.sock
保存退出后,重启mysql服务即可!!
方案:
1. 先看看安装目录
➜ ~ which mysql /usr/local/bin/mysql
既然安装目录存在,则有安装
2.在看下运行状态
➜ tmp ps -ef |grep mysql
发现没在运行
3.直接启动
➜ ~ mysql.server start Starting MySQL ... SUCCESS!
好了,原来是没启动,问题解决,然后widow系统的话是用
service mysql start