저는 맥북을 이용한 개발 중입니다. 이때 mysql이 kill 명령어로 종료시켜도 다른 PID로 바로 재실행되는 현상을 겪었습니다. 저와 같은 분들을 위해 강제로 mysql 종료하는 방법을 공유하겠습니다.
에러 상황
아래와 같이 분명 확인되는 mysql 프로세스의 13202 PID값을 이용해 강제종료(kill -9)했지만 다시 lsof 명령어로 프로세스를 확인한 결과 mysql 프로세스가 새롭게 시작된 모습을 확인할 수 있습니다.
shin@shin-MacBook-Air LaunchDaemons % sudo lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 13202 _mysql 21u IPv6 0xdf64cd106d5941a3 0t0 TCP *:mysql (LISTEN)
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons % sudo kill -9 13202
shin@shin-MacBook-Air LaunchDaemons % sudo lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 13335 _mysql 21u IPv6 0xb530badfaec33273 0t0 TCP *:mysql (LISTEN)
1. /Library/LaunchDaemons 확인하기
해당 경로에는 macOS가 부팅될 때 자동으로 실행되는 데몬 파일들이 존재합니다. 여기서 저는 아래와 같이 'com.oracle.oss.mysql.mysqld.plist'라는 이름의 파일이 존재했습니다.(혹은 com.mysql.mysql.plist 과 같은 이름일 것입니다)
shin@shin-MacBook-Air LaunchDaemons % pwd
/Library/LaunchDaemons
shin@shin-MacBook-Air LaunchDaemons % ls
com.docker.socket.plist com.icerti.iCertiPrintClientDeamon.plist
com.docker.vmnetd.plist com.oracle.oss.mysql.mysqld.plist
shin@shin-MacBook-Air LaunchDaemons %
이 파일은 맥북이 실행될 때 자동으로 mysql이 실행되게 하는 파일이죠. 해당 파일을 열고 내용에 존재하는 옵션값들을 다음과 수정해서 자동 실행을 막았습니다.
# com.oracle.oss.mysql.mysqld 파일
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key> <string>com.oracle.oss.mysql.mysqld</string>
<key>ProcessType</key> <string>Interactive</string>
<key>Disabled</key> <false/>
<key>RunAtLoad</key> <false/>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
<key>AfterInitialDemand</key>
<true/>
</dict>
<key>SessionCreate</key> <true/>
<key>LaunchOnlyOnce</key> <true/>
<key>UserName</key> <string>_mysql</string>
<key>GroupName</key> <string>_mysql</string>
<key>ExitTimeOut</key> <integer>600</integer>
<key>Program</key> <string>/usr/local/mysql/bin/mysqld</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld</string>
<string>--user=_mysql</string>
<string>--basedir=/usr/local/mysql</string>
<string>--datadir=/usr/local/mysql/data</string>
<string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
<string>--log-error=/usr/local/mysql/data/mysqld.local.err</string>
<string>--pid-file=/usr/local/mysql/data/mysqld.local.pid</string>
</array>
<key>WorkingDirectory</key> <string>/usr/local/mysql</string>
<key>EnvironmentVariables</key>
<dict>
<key>MYSQLD_PARENT_PID</key>
<string>1</string>
</dict>
</dict>
</plist>
- RunAtLoad
: true --> false 수정 - LaunchOnlyOnce
: false --> true 수정
2. launchctl 리스트에서 mysql 제거하기
해당 파일(com.oracle.oss.mysql.mysqld.plist)을 수정해도 바로 적용이 되지는 않을 것입니다. 이런 LauchDaemons 파일을 관리하는 launhctl 리스트에서 해당 파일을 제거해야 됩니다. 아래와 같은 명령어를 사용하면 lsof 명령어 결과 mysql이 더 이상 재시작되지 않는 모습을 확인할 수 있습니다.
shin@shin-MacBook-Air LaunchDaemons % sudo launchctl unload /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Password:
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons %
shin@shin-MacBook-Air LaunchDaemons % sudo lsof -i :3306
shin@shin-MacBook-Air LaunchDaemons %
'에러' 카테고리의 다른 글
[AWS] RDS 외부 접속 안될 때 해결 방법(connection timed out) (0) | 2025.04.03 |
---|---|
리액트 빌드 후 CSS 적용 안될 때 시도할만한 방법들 (0) | 2025.03.20 |
Yarn Berry 사용 시 에러 리스트 및 해결 방법 (0) | 2024.11.08 |