본문 바로가기
오류노트

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

by CSEGR 2024. 5. 7.
728x90

내가 보려고 쓰는 오류 노트.....

(맥 M1 pro 기준입니다. !!!!)

 

비밀번호를 잘못 쳐서 MySQL 이 안되는거 였는데, MySQL 이 고장난건줄 알고 냅다 지워버렸다....바보...바보...바보...

새로 세팅하는 과정에서 이러한 문제점을 발견하였다. 

gyuri@baggyuliui-MacBookPro ~ % sudo mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

자꾸 socket이 연결이 안된다고 하였다 .

 

<해결 방법 요약> - cd /usr/local/mysql/bin 로 이동 후 진행

1. mysql 비밀번호를 설정한다 . ( $ mysql_secure_installation )

2. mysql 서비스를 시작한다. ($ sudo /usr/local/mysql/support-files/mysql.server start )

3. mysql 서버를 킨다. ($ mysql -u root -p )

해결 방법 시도

1. 

인터넷에서 계속 service를 restart 하라고 해서 해봤다. 그래도 자꾸 같은 오류가 발생하였다. 

gyuri@baggyuliui-MacBookPro bin % sudo brew services stop mysql
Stopping `mysql`... (might take a while)
==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)
gyuri@baggyuliui-MacBookPro bin % brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

($ brew services restart mysql 이라고 쳐도됨.)

 

2. 

비밀번호를 설정해보라고 해서 비밀번호도 설정하였다. 

gyuri@baggyuliui-MacBookPro bin % mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

비밀번호 설정하고 나니 또 똑같은 오류가 떴다 ..

 

3. 

마지막으로 Chat gpt 에서 제시하는 방법을 써보았다. 

gyuri@baggyuliui-MacBookPro bin % sudo /usr/local/mysql/support-files/mysql.server start

Starting MySQL
 SUCCESS!

MySQL 이 시작되었다는 메세지가 떴다.. 

그리고 나서 mysql 을 실행하는 명령어를 치니 mysql 접속이 되었다!!!!

 

$ mysql -u root -p 

gyuri@baggyuliui-MacBookPro bin % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

 

근데 이 두 개의 명령어가 얼핏보면 같은 기능을 하는 것 같은데,,, 왜 아래 명령어를 사용했을 땐 안되는지 궁금했다. 

brew services start mysql
sudo /usr/local/mysql/support-files/mysql.server start

 

 

gpt 가 이 둘의 차이점은 접근 방식이라고 한다..

나도 Homebrew 통해서 MySQL 설치 했는데,,,,, 왜 안되는건지 모르겠다... 

더 알게된다면 추가로 포스팅 하겠다... !

728x90