bertog's avatar

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

Hi guys I really need some help ...

I've upgrade my Mac (Mojave) to php 7.4 via brew. Everything has worked well since I've restart the PC.

After the restart first has failed Valet, but there's a good Jeffrey's tweet that helped me to sort out the issue.

The drama is come after ... I'm unable to connect to mysql now. I've the "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)".

The sock file is not created in my /tmp folder and everything I've tried is failed miserably ...

I've tried several time to remove and reinstall mysql via brew but it does't work. I've tried to install MySql8 instead of MySql5.7 but no joy ...

I've passed hours on stackoverflow try to figure out what is happen ... but nothing seems to solve my problem ...

I've also tried all those steps:

https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks

Before starting to restore some backups ... can some good guy have some advice for me??

A desperate Guido ...

0 likes
12 replies
Wraith's avatar

You forgot run mysql xD

sudo mysql.server start
bertog's avatar

no MySql is running ... but I cannot connect ...

Wraith's avatar

Show logs:

sudo mysql.server status
bertog's avatar

Ok seems there's some confusion, this is the result of my try:

bertog@Guidos-MacBook-Pro  ~  sudo mysql.server status  1  1562  17:50:40 Password: ERROR! MySQL is not running bertog@Guidos-MacBook-Pro  ~  brew services list  3  1563  19:07:00 Name Status User Plist dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist [email protected] started root /Library/LaunchDaemons/[email protected] nginx started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist bertog@Guidos-MacBook-Pro  ~  sudo mysql.server start   1564  19:07:29 Starting MySQL .Logging to '/usr/local/var/mysql/Guidos-MacBook-Pro.local.err'. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Guidos-MacBook-Pro.local.pid).

No Guidos-MacBook-Pro.local.err file is present in the /usr/local/var/mysql folder ...

Wraith's avatar

if you have error socket (2) means DB is not runing. Might be many ways to fix first

make backup and delete file /etc/my.cnf 

and restart DB

bertog's avatar

A not running MySql was my first guess ... I've been fooled by brew services list who say that mysql is running ...

BTW no /etc/my.cnf present in my system.

Seems no my.cnf at all. I've ran mysql --help and there's no cnf file in this locations:

/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

:(

Wraith's avatar

I suggest don't run any projects on mac book, i was the same, every system upgrade i had to change config again. Now i am using Docker and dont care anymore about configs

1 like
bertog's avatar

Hi Sachin,

I'm on hurry so I've revert to Homestead leaving Valet for now. There's an interesting develop in this.

When I've launched "vagrant up" for the first time Virtual Box has failed due to a permission error on the /tmp/ folder.

I've fixed the permission on /private/tmp (/tmp is a Symlink of this folder) in this way:

sudo chown root:wheel /private/tmp

sudo chmod 1777 /private/tmp

This steps have fixed the Virtual Box error. I thought that could be the same for MySql ...

I've tried again to start MySql using the brew services command and again for brew MySql is started, but no sock file is present in the /tmp/ folder

I think could be a permission error, but I'm not able to solve it now.

Let me know if this could be helpful for you and if you're able to find a solution ...

Guido

chargeDev's avatar
$ sudo rm -rf /usr/local/var/mysql/

$ brew postinstall mysql

$ mysql -uroot
5 likes
patpaskoch's avatar

@chargeDev Hello,

this also fixed my problem, thanks chargeDev.

Can you maybe explain what happen with your 3 lines?

greetings Patrick

Please or to participate in this conversation.