MySQL을 오랜만에 사용하게 됐는데 mysql -u root -p
부터 먹통이었다.😭
에러 내용:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
혹시 mysql.sock
이 있는지 확인해보니.. 없었다.
find / mysql.sock
이유는 모르겠다.. 왜 설치가 안되어있었는지는 정확히 기억은 안나지만 이럴때는 시간이 걸리더라도 재설치를 하는 것이 좋을 거 같았다.
그리고 찾아보니 my.cnf
와 같이 config파일이 존재하는지 which mysql
을 사용해서 찾아보았지만 찾을 수 없었다.
저는 MacOS를 사용하는 데 MySQL를 homebrew로 설치했습니다.
brew를 통해 설치를 마쳤었기 때문에 기존에 설치되었던 내용들을 삭제해주었다.
우선 homebrew를 통해 어떤 것들이 설치되어있는지 확인해보자.
brew services list
Name Status User Plist
dbus stopped
emacs stopped
grafana stopped
mongodb-community started iseunghwan /Users/iseunghwan/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mosquitto started iseunghwan /Users/iseunghwan/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
mysql started iseunghwan /Users/iseunghwan/Library/LaunchAgents/homebrew.mxcl.mysql.plist
unbound stopped
해당경로에 MySQL이 어떻게 되어있는지 먼저 확인한다.
ls -al /usr/local/var/mysql
total 476840
-rw-r----- 1 iseunghwan admin 196608 2 17 2021 #ib_16384_0.dblwr
-rw-r----- 1 iseunghwan admin 8585216 12 30 2020 #ib_16384_1.dblwr
drwxr-x--- 12 iseunghwan admin 384 2 17 2021 #innodb_temp
drwxr-xr-x 41 iseunghwan admin 1312 8 30 22:20 .
drwxrwxr-x 10 iseunghwan admin 320 8 12 00:45 ..
-rw-r----- 1 iseunghwan admin 56 12 30 2020 auto.cnf
-rw-r----- 1 iseunghwan admin 349 1 20 2021 binlog.000007
-rw-r----- 1 iseunghwan admin 72558 1 28 2021 binlog.000008
-rw-r----- 1 iseunghwan admin 94595 1 29 2021 binlog.000009
-rw-r----- 1 iseunghwan admin 65312 2 2 2021 binlog.000010
-rw-r----- 1 iseunghwan admin 49188 2 3 2021 binlog.000011
-rw-r----- 1 iseunghwan admin 115557 2 4 2021 binlog.000012
-rw-r----- 1 iseunghwan admin 1474330 2 9 2021 binlog.000013
-rw-r----- 1 iseunghwan admin 7133 2 10 2021 binlog.000014
-rw-r----- 1 iseunghwan admin 26015728 2 15 2021 binlog.000015
-rw-r----- 1 iseunghwan admin 18202425 2 16 2021 binlog.000016
-rw-r----- 1 iseunghwan admin 3997008 2 17 2021 binlog.000017
-rw-r----- 1 iseunghwan admin 8973369 2 17 2021 binlog.000018
-rw-r----- 1 iseunghwan admin 192 2 17 2021 binlog.index
-rw------- 1 iseunghwan admin 1676 12 30 2020 ca-key.pem
-rw-r--r-- 1 iseunghwan admin 1112 12 30 2020 ca.pem
-rw-r--r-- 1 iseunghwan admin 1112 12 30 2020 client-cert.pem
-rw------- 1 iseunghwan admin 1676 12 30 2020 client-key.pem
drwxr-x--- 6 iseunghwan admin 192 2 10 2021 grafana
-rw-r----- 1 iseunghwan admin 3401 12 30 2020 ib_buffer_pool
-rw-r----- 1 iseunghwan admin 50331648 2 17 2021 ib_logfile0
-rw-r----- 1 iseunghwan admin 50331648 2 17 2021 ib_logfile1
-rw-r----- 1 iseunghwan admin 12582912 2 17 2021 ibdata1
-rw-r----- 1 iseunghwan admin 12582912 2 17 2021 ibtmp1
-rw-r----- 1 iseunghwan admin 64941 8 30 22:36 iseunghwan-ui-MacBookPro.local.err
drwxr-x--- 23 iseunghwan admin 736 2 10 2021 mobiusdb
drwxr-x--- 8 iseunghwan admin 256 12 30 2020 mysql
-rw-r----- 1 iseunghwan admin 25165824 2 17 2021 mysql.ibd
drwxr-x--- 110 iseunghwan admin 3520 12 30 2020 performance_schema
-rw------- 1 iseunghwan admin 1680 12 30 2020 private_key.pem
-rw-r--r-- 1 iseunghwan admin 452 12 30 2020 public_key.pem
-rw-r--r-- 1 iseunghwan admin 1112 12 30 2020 server-cert.pem
-rw------- 1 iseunghwan admin 1676 12 30 2020 server-key.pem
drwxr-x--- 3 iseunghwan admin 96 12 30 2020 sys
-rw-r----- 1 iseunghwan admin 12582912 2 17 2021 undo_001
-rw-r----- 1 iseunghwan admin 12582912 2 17 2021 undo_002
지우기 전에 작동 중인 서버를 멈춰준다.
brew services stop mysql
Stopping `mysql`... (might take a while)
==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)
rm -rf /usr/local/var/mysql
위에서 확인한 디렉토리를 삭제 후 homebrew에서도 제거 해준다.
brew uninstall mysql
Uninstalling /usr/local/Cellar/mysql/8.0.22_1... (294 files, 296.5MB)
다음 명령어를 통해서 완전히 제거가 되었는지 확인한다.
brew list | grep mysql
brew install mysql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 6 taps (homebrew/core, homebrew/cask, homebrew/services, mongodb/brew, brewsci/bio and adoptopenjdk/openjdk).
==> New Formulae
...
Removing: /usr/local/Cellar/berkeley-db/18.1.32_1... (5,672 files, 116.5MB)
==> Checking for dependents of upgraded formulae...
==> No broken dependents found!
==> Caveats
==> mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To start mysql:
brew services start mysql
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql
설치가 완료되었다면 실행시켜보자
brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
모든 작업을 마쳤다면 이제 새로 설치된 MySQL를 이용하기 전에, 초기 설정 값에서 비밀번호를 설정해준다.
mysql_secure_installation
비밀번호 설정 후, .sql
파일을 dump해서 나머지 작업을 할 수 있었다.