Installing mysql on leopard: "Can't connect to local MySQL server through socket"
Solution 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.
Solution 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
Admin
Updated on June 19, 2022Comments
-
Admin almost 2 years
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.
-
Dawn Green almost 8 yearsWorked for me after many other attempts. Only difference was I used 'sudo vim' to modify the file. Thank you.