[MySQL] max_connection 최대 접속 인원 늘리기
- 데이터베이스 / MySQL
- 2022. 9. 28.
Too many connections
개발을 하다 보면 여러 서버를 만들어서 데이터베이스에 접근하게 됩니다. 하지만 다음과 같은 에러를 마주하면 최대 접속 숫자를 늘려줘야 합니다.
# ERROR 1040 (08004): Too many connections
# Host 192.168.0.X Host is blocked because of many connection errors MySQL
▼ max_connecions 값을 확인합니다. 동시접속에 대한 값입니다. 기본값은 보통 151로 지정되어 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> show variables like '%max_connect%'; |

▼ 다음 명령을 통해 현재 접속 중인 커넥션을 확인할 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> show status like 'threads_connected'; |

▼ 이제 max_connections 숫자를 변경해보겠습니다. 별도로 서버를 재시작하지 않더라도 잘 동작합니다만 만약 MySQL 서버를 재실행한다면 해당 값은 기본값으로 돌아오게 됩니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> set global max_connections=300; |
my.cnf
▼ 때문에 다음과 같이 my.cnf를 찾아서 수정해줍니다. [mysqld] 구문 아래 커스텀 옵션들을 정의할 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[mysqld] | |
max_connections = 300 |
▼ macOS 기준 해당 파일(my.cnf)의 위치는 다음과 같습니다. 리눅스나 윈도우의 경우 경로가 조금 다를 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/opt/homebrew/etc/my.cnf |
▼ 이제 서버를 재시작해줍니다. (brew 패키지 매니저)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew services restart mysql; |
▼ mysqladmin 유틸을 이용해서 processlist를 확인할 수도 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysqladmin -uroot -p processlist |
'데이터베이스 > MySQL' 카테고리의 다른 글
[MySQL] 데이터베이스 기초 - 테이블 (Table) 이름 변경 (0) | 2022.10.03 |
---|---|
[MySQL] 데이터베이스 기초 - 사용자 관리 및 접속 (0) | 2022.10.01 |
[MySQL] 맥 MySQL 설치 후 터미널 PATH 경로 설정 (0) | 2022.09.23 |
[MySQL] 데이터베이스 기초 - 테이블 (Table) 정의 (0) | 2022.09.22 |
[MySQL] 데이터베이스 기초 - 인덱스 (Index) (2) | 2022.09.15 |