• Skip to main content
  • Skip to primary sidebar

WP Dev

Guides, plugins and themes for WordPress

You are here: Home / General / Fix mariadb ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2) on macOS Monterey 12.6 using homebrew

Fix mariadb ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2) on macOS Monterey 12.6 using homebrew

November 7, 2022 by Ciprian Tepes Leave a Comment

I have recently upgraded my macOS to Monterey (version 12.6) and mariadb (mysql) stopped working. I tried to run brew services restart mariadb and it didn’t show any error so I thought everything works fine.

However, when I tried to access the mysql using either mariadb or mysql I was getting this ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2).

I spent a lot of time trying to fix the error but I couldn’t. However, someone said in a comment on this post https://getgrav.org/blog/macos-monterey-apache-mysql-vhost-apc that it will help to backup then remove the contents of the mysql folder.

Solution for ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2)

This worked for me on macOS Monterey 12.6:

Step 1. Backup the mysql folder and your databases

In your terminal, copy the contents of mysql folder:

$ mkdir /usr/local/var/mysql__BKP
$ cp -R /usr/local/var/mysql/* /usr/local/var/mysql__BKP
$ mysqldump --all-databases > sql_file.sql

Step 2. Uninstall (remove) using homebrew and remove the content from the mysql folder

$ brew services stop mariadb
$ brew uninstall mariadb
$ brew cleanup
$ rm -rf /usr/local/var/mysql/*

Step 3. Install mariadb using homebrew and start the service

$ brew install mariadb
$ brew start mariadb

Once you do that, a popup should open asking you to allow network connections:

Homebrew mariadb allow network connection on macOS Monterey 12.6

Warning

If you copy back the files from your backup folder BEFORE starting the mariadb service using brew service start mariadb you’ll still get the ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2)

Step 4. Copy your databases back to mysql

That should be all you need to fix the connection error.

Filed Under: General

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Fix mariadb ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2) on macOS Monterey 12.6 using homebrew
  • Fix WordPress login redirect loop when accessing wp-admin
  • Fix easyengine error for global-nginx-proxy
  • Replace WordPress Widget Title Tag

Recent Comments

No comments to show.

Copyright © 2023 WP Dev ยท Powered by WordPress

Last Updated on 4 months by admin