I brew installed mysql and had the same issue after my laptop battery died and forced an incomplete shutdown. It's worth running mysqld to check things and ensure MySQL shut down properly last time. If it had a 'dirty' shutdown (e.g. if a laptop battery forces a system shutdown) this should clean it up. Then you can start MySQL server again: mysql.server start.
– Dave EverittJun 16 '17 at 19:05

None of the answers here worked for me either.
– AntimonyDec 6 '17 at 0:13

@Liron, did you fix the issue that you are facing? I am facing the same issue with no help.
– BuddyNov 5 '17 at 12:56

@EB it's been a while since I had this issue but looking back at my comment, you tried the workaround to install an older version of MySQL? Other than that I'm out of ideas unfortunately.
– Liron YahdavNov 6 '17 at 1:52

@Esteban MySQL will try to connect to the unix socket if you tell it to connect to "localhost". If you tell it to connect to 127.0.0.1 you are forcing it to connect to the network socket. So probably you have MySQL configured to only listen to the network socket and not to the file system socket. (Source: serverfault.com/a/295300/59101)
– Ardee AramDec 29 '16 at 14:05

Hi @PratikKhadka, the error you are getting now, means mysql is running, and you have authentication problem. According to the error message you posted, you are using username as 'user' and using no password. You should use a valid username and password. I suggest you to check the following link; "forums.mysql.com/read.php?34,140320,140324"
– BerkJun 30 '18 at 15:17

This worked for me and should be selected as the right answer to this question. After starting the services, I could set the password for mysql using the mysql_secure_installation
– The RoySep 16 '18 at 5:54

Please explain with some brief examples how the link you provided, helped you out. Links can disappear, and therefore this can be a reason that your answer might be deleted.
– Kurt Van den BrandenDec 27 '16 at 11:59

Since I spent quite some time trying to solve this and always came back to this page when looking for this error, I'll leave my solution here hoping that somebody saves the time I've lost. Although in my case I am using mariadb rather than MySql, you might still be able to adapt this solution to your needs.

My problem

is the same, but my setup is a bit different (mariadb instead of mysql):

So I run the command with superuser privileges instead and after entering my password I got:

$ sudo mysql -uroot
MariaDB [(none)]>

Notes:

I'm not quite sure about the groups where you have to add the socket, first I had it [client-server] but then I figured [client] should be enough. So I changed it and it still works.

When running mariadb_config | grep socket I get:
--socket [/tmp/mysql.sock]
which is a bit confusing since it seems that /usr/local/mariadb/data/mariadb.sock is the actual place (at least on my machine)

I wonder where I can configure the /usr/local/mariadb/data/mariadb.sock to actually be /tmp/mysql.sockso I can use the default settings instead of having to edit my .my.cnf (but I'm too tired now to figure that out...)

At some point I also did things mentioned in other answers before coming up with this.

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