Can't connect to local MySQL server through so

2019-01-16 03:26发布

I recently tried installing MySQL with homebrew (brew install mysql) and when I try to run it I get the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

There is no /tmp/mysql.sock nor a /var/lib/mysql.sock.

I've searched and haven't found any mysql.sock file.

How can I fix this?

12条回答
该账号已被封号
2楼-- · 2019-01-16 04:19

The file /tmp/mysql.sock is probably a Named-Pipe, since it's in a temporary folder. A named pipe is a Special-File that never gets permanently stored.

If we make two programs, and we want one program to send a message to another program, we could create a text file. We have one program write something in the text file and the other program read what our other program wrote. That's what a pipe is, except it doesn't write the file to our computer hard disk, IE doesn't permanently store the file (like we do when we create a file and save it.)

A Socket is the exact same as a Pipe. The difference is that Sockets are usually used over a network -- between computers. A Socket sends information to another computer, or receives information from another computer. Both Pipes and Sockets use a temporary file to share so that they can 'communicate'.

It's difficult to discern which one MySql is using in this case. Doesn't matter though.

The command mysql.server start should get the 'server' (program) running its infinite loop that will create that special-file and wait for changes (listen for writes).

After that, a common issue might be that the MySql program doesn't have permission to create a file on your machine, so you might have to give it root privileges

sudo mysql.server start
查看更多
够拽才男人
3楼-- · 2019-01-16 04:22

Looks like your mysql server is not started. I usually run the stop command and then start it again:

mysqld stop
mysql.server start

Same error, and this works for me.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-16 04:23

I faced the same problem on my mac and solved it, by following the following tutorials

https://mariadb.com/resources/blog/installing-mariadb-10116-mac-os-x-homebrew

But don't forget to kill or uninstall the old version before continuing.

Commands:

brew uninstall mariadb

xcode-select --install

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - See more at: https://mariadb.com/resources/blog/installing-mariadb-10116-mac-os-x-homebrew#sthash.XQoxRoJp.dpuf

brew doctor

brew update

brew info mariadb

brew install mariadb

mysql_install_db

mysql.server start
查看更多
孤傲高冷的网名
5楼-- · 2019-01-16 04:26

When you got the server running via

mysql.server start

you should see the socket in /tmp/mysql.sock. However, the system seems to expect it in /var/mysql/mysql.sock. To fix this, you have to create a symlink in /var/mysql:

sudo mkdir /var/mysql

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

This solved it for me. Now my phpMyAdmin works happily with localhost and 127.0.0.1.

Credit goes to Henry

查看更多
淡お忘
6楼-- · 2019-01-16 04:26

Try to connect using "127.0.0.1" instead "localhost".

查看更多
相关推荐>>
7楼-- · 2019-01-16 04:29

just to complete this thread. therefore MAMP (PRO) is used pretty often

the path here is

/Applications/MAMP/tmp/mysql/mysql.sock
查看更多
登录 后发表回答