问题
I installed mysql via homebrew. I ran the two commands brew suggests:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
When I tried to run the mysql_secure_installation script, I receive this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
A separate thread led me to believe it had to do with permissions: connect to local MySQL server through socket
I ran the suggested commands substituting their mysql directory with
/usr/local/var/mysql
Yet, the problem persists. Help!
回答1:
Your socket is probably being created in a non-standard location. My Homebrew installation creates it in /tmp/mysql.sock
for instance.
If you can connect to the server over the TCP/IP socket, run this:
SHOW VARIABLES LIKE '%sock%';
Otherwise, try to look for it somewhere on your system:
find / -name mysql.sock
回答2:
What is the default socket defined in /etc/php.ini?
Try running
cat /etc/php.ini | grep "mysql.default_socket"
来源:https://stackoverflow.com/questions/14821982/mountain-lion-cant-connect-to-local-mysql-server-through-socket-tmp-mysql-so