Installing mysql on leopard: “Can't connect to local MySQL server through socket”

旧城冷巷雨未停 提交于 2019-11-30 03:55:23

问题


I migrated to a new machine and used migration assistant to copy across my files (which seemed to copy across the DBs) but I had to use macports to install Mysql (whereas last time I compiled from source via Dan Benjamin's guide). For some reason, mysql is intermittently throwing the following error;

Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)

It does this no matter what I try, which has included setting the socket in /opt/local/etc/mysql5/my.cnf. Previously I've managed to temporarily fix this by restarting the machine, but right now it just doesn't want to know, despite grep mysql telling me I seem to have a pid;

  0    46     1   0   0:00.01 ??         0:00.01 /opt/local/bin/daemondo --label=mysql5 --start-cmd /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper restart ; --pid=none
  0    70     1   0   0:00.01 ??         0:00.01 /bin/sh /opt/local/lib/mysql5/bin/mysqld_safe --datadir=/opt/local/var/db/mysql5 --pid-file=/opt/local/var/db/mysql5/localhost.pid
 74   100    70   0   0:09.22 ??         1:02.68 /opt/local/libexec/mysqld --basedir=/opt/local --datadir=/opt/local/var/db/mysql5 --user=mysql --pid-file=/opt/local/var/db/mysql5/localhost.pid --socket=/tmp/mysql.sock
501 66217 65266   0   0:00.00 ttys001    0:00.00 grep mysql

How do I fix this? Are there any steps I can take next? I've been trying for a few weeks now and I've read round all relevant blog posts, so I'm completely out of ideas.


回答1:


This is way after the fact, but here's what I did:

touch /opt/local/var/run/mysql5/mysqld.sock
vi /opt/local/etc/mysql5/my.cnf

Add the following lines to my.cnf:

[mysqld_safe]
socket = /opt/local/var/run/mysql5/mysqld.sock

[client]
socket = /opt/local/var/run/mysql5/mysqld.sock

This should allow you to connect. This worked for me on both Leopard and Snow Leopard.




回答2:


Rob is correct. See this link for fuller explanation: https://discussions.apple.com/docs/DOC-3082

Note especially this comment which pertains to your issue:

The default path for the MySQL socket is not appropriate for MacOS X. Until it is changed, MySQL will not be able to communicate...

So, do what Rob says (though it may be different for Lion), and launch your MySQL:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist

EDIT: Also see this link: http://dev.mysql.com/doc/refman/4.1/en/problems-with-mysql-sock.html

EDIT: See this question: MySQL Server does not start on Raspberry Pi



来源:https://stackoverflow.com/questions/1136808/installing-mysql-on-leopard-cant-connect-to-local-mysql-server-through-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!